mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-04 06:08:26 +02:00
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>
This commit is contained in:
parent
d1bdaf3fb2
commit
d6cd614dac
@ -63,10 +63,19 @@
|
|||||||
* Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they
|
* 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
|
* are not representable as absolute values of their type. This is the same
|
||||||
* as with *abs()
|
* as with *abs()
|
||||||
|
* @see FFNABS()
|
||||||
*/
|
*/
|
||||||
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
|
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
|
||||||
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
|
#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 FFMAX(a,b) ((a) > (b) ? (a) : (b))
|
||||||
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
|
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
|
||||||
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
|
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user