Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-09-03 03:17:24 +0300
committerMichael Niedermayer <michael@niedermayer.cc>2015-09-03 10:05:50 +0300
commitd6cd614dac579850076ae312c29c4188f8659e46 (patch)
tree045f9bdcf56740a093a7f081649a752fe0dbeee7 /libavutil/common.h
parentd1bdaf3fb2c45020f72a378bb64eab1bf136581c (diff)
avutil/common: Add FFNABS()
This macro avoids the undefined corner case with the *_MIN values Previous version Reviewed-by: Ganesh Ajjanagadde <gajjanag@mit.edu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil/common.h')
-rw-r--r--libavutil/common.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/libavutil/common.h b/libavutil/common.h
index 14343d977b..38eae28d2a 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -63,10 +63,19 @@
* Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they
* are not representable as absolute values of their type. This is the same
* as with *abs()
+ * @see FFNABS()
*/
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
+/**
+ * Negative Absolute value.
+ * this works for all integers of all types.
+ * As with many macros, this evaluates its argument twice, it thus must not have
+ * a sideeffect, that is FFNABS(x++) has undefined behavior.
+ */
+#define FFNABS(a) ((a) <= 0 ? (a) : (-(a)))
+
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))