[FFmpeg-cvslog] avutil/common: Add FFNABS()

Michael Niedermayer git at videolan.org
Thu Nov 26 17:54:54 CET 2015


ffmpeg | branch: release/2.5 | Michael Niedermayer <michael at niedermayer.cc> | Thu Sep  3 02:17:24 2015 +0200| [8ebeefecf71ed6dbc285a240f9852077086a06d3] | committer: Michael Niedermayer

avutil/common: Add FFNABS()

This macro avoids the undefined corner case with the *_MIN values

Previous version Reviewed-by: Ganesh Ajjanagadde <gajjanag at mit.edu>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit d6cd614dac579850076ae312c29c4188f8659e46)

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8ebeefecf71ed6dbc285a240f9852077086a06d3
---

 libavutil/common.h |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libavutil/common.h b/libavutil/common.h
index a48959d..526f5c6 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))



More information about the ffmpeg-cvslog mailing list