From: Michael Niedermayer <mich...@niedermayer.cc> This function avoids the undefined corner cases which affects other absolute value functions and macros
Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc> --- libavutil/common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavutil/common.h b/libavutil/common.h index 14343d9..89906be 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -63,10 +63,14 @@ * 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 +#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)) -- 1.7.9.5 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel