summaryrefslogtreecommitdiff
path: root/libavutil/mathematics.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-06-02 19:00:18 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-06-02 19:00:18 +0200
commite9add0d85b38db8efebd53bed83125945103e11f (patch)
treecae8912f4a12b79fff260d535b502d26382e6c33 /libavutil/mathematics.c
parent4956d0e5a6a555d31345c913485bcc4e0a53481e (diff)
av_add_stable: Add fast special case where step can be represented exactly
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mathematics.c')
-rw-r--r--libavutil/mathematics.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index c8f1e1cd89..df7d0d88bf 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -188,9 +188,17 @@ simple_round:
int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)
{
+ int64_t m, d;
+
if (inc != 1)
inc_tb = av_mul_q(inc_tb, (AVRational) {inc, 1});
+ m = inc_tb.num * (int64_t)ts_tb.den;
+ d = inc_tb.den * (int64_t)ts_tb.num;
+
+ if (m % d == 0)
+ return ts + m / d;
+
if (av_cmp_q(inc_tb, ts_tb) < 0) {
//increase step is too small for even 1 step to be representable
return ts;