diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-09-03 02:17:24 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-11-19 03:51:38 +0100 |
commit | ca89c0afdb1450b7e7644dc4b6eea0cc323dd0e6 (patch) | |
tree | 834b2c1ead801ce04c2ca9e8c44bf90ec5038985 | |
parent | 3311efe2c22900c7a0e4f54a9759c987c089f488 (diff) | |
download | ffmpeg-ca89c0afdb1450b7e7644dc4b6eea0cc323dd0e6.tar.gz |
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>
(cherry picked from commit d6cd614dac579850076ae312c29c4188f8659e46)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavutil/common.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libavutil/common.h b/libavutil/common.h index 223895481b..11f88efaf3 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)) |