summaryrefslogtreecommitdiff
path: root/ffmpeg/libavutil/rational.c
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-12-29 12:19:38 +0000
committerTim Redfern <tim@eclectronics.org>2013-12-29 12:19:38 +0000
commitf7813a5324be39d13ab536c245d15dfc602a7849 (patch)
treefad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavutil/rational.c
parentb7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff)
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavutil/rational.c')
-rw-r--r--ffmpeg/libavutil/rational.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ffmpeg/libavutil/rational.c b/ffmpeg/libavutil/rational.c
index 768f252..ec2f2e5 100644
--- a/ffmpeg/libavutil/rational.c
+++ b/ffmpeg/libavutil/rational.c
@@ -26,7 +26,6 @@
*/
#include "avassert.h"
-//#include <math.h>
#include <limits.h>
#include "common.h"
@@ -111,11 +110,14 @@ AVRational av_d2q(double d, int max)
int64_t den;
if (isnan(d))
return (AVRational) { 0,0 };
- if (isinf(d))
+ if (fabs(d) > INT_MAX + 3LL)
return (AVRational) { d < 0 ? -1 : 1, 0 };
exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
den = 1LL << (61 - exponent);
- av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
+ // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64
+ av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);
+ if ((!a.num || !a.den) && d && max>0 && max<INT_MAX)
+ av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, INT_MAX);
return a;
}