[FFmpeg-devel] [PATCH] configure, avutil/libm: add fmax, fmaxf, fmin, fminf support

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Oct 15 14:18:02 CEST 2015


It has been demonstrated that using libc provided floating point
functions is beneficial, in the context of fabs() vs FFABS.

Unfortunately, MSVC 2012 (and earlier) lack the ISO C99 fmax, fmaxf,
fmin, fminf functions. This patch adds them, thus making their usage in
FFmpeg safe.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 configure        |  9 +++++++++
 libavutil/libm.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/configure b/configure
index 52a65a4..571d4f2 100755
--- a/configure
+++ b/configure
@@ -1766,6 +1766,10 @@ MATH_FUNCS="
     exp2
     exp2f
     expf
+    fmax
+    fmaxf
+    fmin
+    fminf
     isinf
     isnan
     ldexpf
@@ -5278,6 +5282,11 @@ disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersi
 
 atan2f_args=2
 copysign_args=2
+fmax_args=2
+fmaxf_args=2
+fmin_args=2
+fminf_args=2
+fmin_args=2
 ldexpf_args=2
 powf_args=2
 
diff --git a/libavutil/libm.h b/libavutil/libm.h
index 6c17b28..a4a2cc0 100644
--- a/libavutil/libm.h
+++ b/libavutil/libm.h
@@ -82,6 +82,34 @@ static av_always_inline float cbrtf(float x)
 #define exp2f(x) ((float)exp2(x))
 #endif /* HAVE_EXP2F */
 
+#if !HAVE_FMAX
+static av_always_inline av_const double fmax(double x, double y)
+{
+    return (x >= y) ? x : y;
+}
+#endif /* HAVE_FMAX */
+
+#if !HAVE_FMAXF
+static av_always_inline av_const float fmaxf(float x, float y)
+{
+    return (x >= y) ? x : y;
+}
+#endif /* HAVE_FMAXF */
+
+#if !HAVE_FMIN
+static av_always_inline av_const double fmin(double x, double y)
+{
+    return (x <= y) ? x : y;
+}
+#endif /* HAVE_FMIN */
+
+#if !HAVE_FMINF
+static av_always_inline av_const float fminf(float x, float y)
+{
+    return (x <= y) ? x : y;
+}
+#endif /* HAVE_FMINF */
+
 #if !HAVE_ISINF
 static av_always_inline av_const int isinf(float x)
 {
-- 
2.6.1



More information about the ffmpeg-devel mailing list