Skip to content
Snippets Groups Projects
Commit 1405782c authored by Stefano Sabatini's avatar Stefano Sabatini
Browse files

Avoid cast of double nan to int.

It may cause exceptions on some platform.

Originally committed as revision 25311 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8bf256bc
No related branches found
No related tags found
No related merge requests found
...@@ -96,10 +96,12 @@ AVRational av_sub_q(AVRational b, AVRational c){ ...@@ -96,10 +96,12 @@ AVRational av_sub_q(AVRational b, AVRational c){
AVRational av_d2q(double d, int max){ AVRational av_d2q(double d, int max){
AVRational a; AVRational a;
#define LOG2 0.69314718055994530941723212145817656807550013436025 #define LOG2 0.69314718055994530941723212145817656807550013436025
int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); int exponent;
int64_t den= 1LL << (61 - exponent); int64_t den;
if (isnan(d)) if (isnan(d))
return (AVRational){0,0}; return (AVRational){0,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); av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
return a; return a;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment