summaryrefslogtreecommitdiff
path: root/libavutil/internal.h
diff options
context:
space:
mode:
authorGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-25 08:07:08 -0800
committerGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-25 10:12:49 -0800
commit11388b5a8f187d5b7c8a28437e95762485f51ed8 (patch)
treec0d1a31ee3cd1ba5e3e30121bd4aa6a6cc84a80b /libavutil/internal.h
parent73616b1f21a776aef814ca036d783eede28773a7 (diff)
lavu/internal: add ff_exp10
Fast, reasonably accurate 10^x. Alternative of detection of libm exp10 at configure time is not worth the trouble, since it is anyway not POSIX or ISO C, and currently only the GNU libm has it. Furthermore, GNU libm's variant is ~ 2x slower, and is ironically not correctly rounded (2 ulp off) to justify all that slowdown. Reviewed-by: James Almer <jamrial@gmail.com> Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Diffstat (limited to 'libavutil/internal.h')
-rw-r--r--libavutil/internal.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavutil/internal.h b/libavutil/internal.h
index f86b7fb741..076aa47f3d 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -292,6 +292,25 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
return res;
}
+/**
+ * Compute 10^x for floating point values. Note: this function is by no means
+ * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
+ * For instance, maximum relative error for the double precision variant is
+ * ~ 1e-13 for very small and very large values.
+ * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
+ * some inputs.
+ * @param x exponent
+ * @return 10^x
+ */
+static av_always_inline double ff_exp10(double x)
+{
+ return exp2(M_LOG2_10 * x);
+}
+
+static av_always_inline float ff_exp10f(float x)
+{
+ return exp2f(M_LOG2_10 * x);
+}
/**
* A wrapper for open() setting O_CLOEXEC.