summaryrefslogtreecommitdiff
path: root/libavutil/common.h
diff options
context:
space:
mode:
authorMark Reid <mindmark@gmail.com>2021-11-14 22:22:20 -0800
committerJames Almer <jamrial@gmail.com>2021-11-15 16:50:08 -0300
commitc3502f4f75583a530bc54e2cb6754236d72f204b (patch)
treebd4b459538e7298a8dc4002916861690644ca3f6 /libavutil/common.h
parenta7dfa6b446e8ced9f25efd0597e6073e6b22a94b (diff)
libavutil/common: clip nan value to amin
Changes av_clipf to return amin if a is nan. Before if a is nan av_clipf_c returned nan and av_clipf_sse would return amax. Now the both should behave the same. This works because nan > amin is false. The max(nan, amin) will be amin. Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/common.h')
-rw-r--r--libavutil/common.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/libavutil/common.h b/libavutil/common.h
index 3cc1f07566..3eb9bc5f74 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -379,6 +379,8 @@ static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) {
/**
* Clip a float value into the amin-amax range.
+ * If a is nan or -inf amin will be returned.
+ * If a is +inf amax will be returned.
* @param a value to clip
* @param amin minimum value of the clip range
* @param amax maximum value of the clip range
@@ -389,13 +391,13 @@ static av_always_inline av_const float av_clipf_c(float a, float amin, float ama
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
if (amin > amax) abort();
#endif
- if (a < amin) return amin;
- else if (a > amax) return amax;
- else return a;
+ return FFMIN(FFMAX(a, amin), amax);
}
/**
* Clip a double value into the amin-amax range.
+ * If a is nan or -inf amin will be returned.
+ * If a is +inf amax will be returned.
* @param a value to clip
* @param amin minimum value of the clip range
* @param amax maximum value of the clip range
@@ -406,9 +408,7 @@ static av_always_inline av_const double av_clipd_c(double a, double amin, double
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
if (amin > amax) abort();
#endif
- if (a < amin) return amin;
- else if (a > amax) return amax;
- else return a;
+ return FFMIN(FFMAX(a, amin), amax);
}
/** Compute ceil(log2(x)).