This simplifies and cleans up the code. Furthermore, it is much faster due to absence of the slow log computation.
Unified · Split
| @@ -106,14 +106,14 @@ AVRational av_sub_q(AVRational b, AVRational c) · 105 unmodified lines | ||
| 106 | 106 | AVRational av_d2q(double d, int max) |
| 107 | 107 | { |
| 108 | 108 | AVRational a; |
| 109 | −#define LOG2 0.69314718055994530941723212145817656807550013436025 | |
| 110 | 109 | int exponent; |
| 111 | 110 | int64_t den; |
| 112 | 111 | if (isnan(d)) |
| 113 | 112 | return (AVRational) { 0,0 }; |
| 114 | 113 | if (fabs(d) > INT_MAX + 3LL) |
| 115 | 114 | return (AVRational) { d < 0 ? -1 : 1, 0 }; |
| 116 | − exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); | |
| 115 | + frexp(d, &exponent); | |
| 116 | + exponent = FFMAX(exponent-1, 0); | |
| 117 | 117 | den = 1LL << (61 - exponent); |
| 118 | 118 | // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64 |
| 119 | 119 | av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max); |