diff options
Diffstat (limited to 'src/libffmpeg/libavutil/rational.c')
-rw-r--r-- | src/libffmpeg/libavutil/rational.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/libffmpeg/libavutil/rational.c b/src/libffmpeg/libavutil/rational.c index 104499929..4a7b0edf7 100644 --- a/src/libffmpeg/libavutil/rational.c +++ b/src/libffmpeg/libavutil/rational.c @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - + /** * @file rational.c * Rational numbers @@ -26,7 +26,7 @@ //#include <math.h> #include <limits.h> - + #include "common.h" #include "mathematics.h" #include "rational.h" @@ -42,7 +42,7 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max) a1= (AVRational){nom, den}; den=0; } - + while(den){ int64_t x = nom / den; int64_t next_den= nom - den*x; @@ -57,10 +57,10 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max) den= next_den; } assert(ff_gcd(a1.num, a1.den) == 1); - + *dst_nom = sign ? -a1.num : a1.num; *dst_den = a1.den; - + return den==0; } @@ -76,8 +76,7 @@ AVRational av_mul_q(AVRational b, AVRational c){ * returns b/c. */ AVRational av_div_q(AVRational b, AVRational c){ - av_reduce(&b.num, &b.den, b.num * (int64_t)c.den, b.den * (int64_t)c.num, INT_MAX); - return b; + return av_mul_q(b, (AVRational){c.den, c.num}); } /** @@ -92,8 +91,7 @@ AVRational av_add_q(AVRational b, AVRational c){ * returns b-c. */ AVRational av_sub_q(AVRational b, AVRational c){ - av_reduce(&b.num, &b.den, b.num * (int64_t)c.den - c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX); - return b; + return av_add_q(b, (AVRational){-c.num, c.den}); } /** @@ -102,7 +100,8 @@ AVRational av_sub_q(AVRational b, AVRational c){ */ AVRational av_d2q(double d, int max){ AVRational a; - int exponent= FFMAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0); +#define LOG2 0.69314718055994530941723212145817656807550013436025 + int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); int64_t den= 1LL << (61 - exponent); av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); |