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
106106 AVRational av_d2q(double d, int max)
107107 {
108108 AVRational a;
109−#define LOG2 0.69314718055994530941723212145817656807550013436025
110109 int exponent;
111110 int64_t den;
112111 if (isnan(d))
113112 return (AVRational) { 0,0 };
114113 if (fabs(d) > INT_MAX + 3LL)
115114 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);
117117 den = 1LL << (61 - exponent);
118118 // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64
119119 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