[FFmpeg-devel] [PATCH 3/3] lavu/internal: tighten errors for avpriv_exp10

Ganesh Ajjanagadde gajjanagadde at gmail.com
Fri Dec 25 18:11:56 CET 2015


This tightens the errors by doing a first order Taylor approximation of
one obvious source of error. This results in negligible runtime
slowdown, but improves worst case relative error by ~ 30%, worst case
ulp count from  673 to 391. Another illustration is:
arg   : -303.137207600000010643270798027515
exp10 : 7.2910890073523505e-304, 2 ulp
exp10l: 7.2910890073523489e-304, 0 ulp
simple: 7.2910890073526541e-304, 377 ulp
corr  : 7.2910890073524274e-304, 97 ulp
real  : 7.2910890073523489e-304, 0 ulp
next  : 7.2910890073533033e-304, 1178 ulp
prev  : 7.2910890073513954e-304, 1178 ulp

where next, prev denote:
exp10l(nextafter(x, INFINITY))
exp10l(nextafter(x, -INFINITY)),
and simple the exp2(M_LOG2_10 * x), corr this approach.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavutil/internal.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavutil/internal.h b/libavutil/internal.h
index ae11601..b6d72b7 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -304,7 +304,9 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
  */
 static av_always_inline double avpriv_exp10(double x)
 {
-    return exp2(M_LOG2_10 * x);
+    /* log(2)*(log2(10) - (double)log2_10) */
+    static const double log2_10_eps = 1.02495895001049072e-16;
+    return exp2(M_LOG2_10 * x) * (1 + log2_10_eps * x);
 }
 
 static av_always_inline float avpriv_exp10f(float x)
-- 
2.6.4



More information about the ffmpeg-devel mailing list