History

avutil/rational: use frexp rather than ad-hoc log to get floating point exponent

This simplifies and cleans up the code. Furthermore, it is much faster due to absence of the slow log computation.

Ganesh Ajjanagadde committed 11 years ago

Commit 8d9f86b1 parent 865f6f41 file · +2 −2Browse files

Unified · Split

libavutil/rational.c+2−2
@@ -106,14 +106,14 @@ AVRational av_sub_q(AVRational b, AVRational c) · 105 unmodified lines
106AVRational av_d2q(double d, int max)106AVRational av_d2q(double d, int max)
107{107{
108 AVRational a;108 AVRational a;
109#define LOG2 0.69314718055994530941723212145817656807550013436025
110 int exponent;109 int exponent;
111 int64_t den;110 int64_t den;
112 if (isnan(d))111 if (isnan(d))
113 return (AVRational) { 0,0 };112 return (AVRational) { 0,0 };
114 if (fabs(d) > INT_MAX + 3LL)113 if (fabs(d) > INT_MAX + 3LL)
115 return (AVRational) { d < 0 ? -1 : 1, 0 };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 den = 1LL << (61 - exponent);117 den = 1LL << (61 - exponent);
118 // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64118 // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64
119 av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);119 av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t