]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/internal.h
Merge commit '64f8c439fd663fec4d57ac21af572d498fe21f7a'
[ffmpeg] / libavutil / internal.h
index 8d2d8759bf0dd20f2e472401ad1ff4849b04a7cc..076aa47f3d91a45b83cd2596f2d48a0be46e17fd 100644 (file)
@@ -281,7 +281,7 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
     if (a >=  9223372036854775808.0)
         return amax;
     if (a <= -9223372036854775808.0)
-       return amin;
+        return amin;
 
     // safe to call llrint and clip accordingly
     res = llrint(a);
@@ -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.