diff mbox series

[FFmpeg-devel,1/6] avutil/common: Add FFABSU() for a signed -> unsigned ABS

Message ID 20210123221056.3366-1-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel,1/6] avutil/common: Add FFABSU() for a signed -> unsigned ABS | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer Jan. 23, 2021, 10:10 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavutil/common.h | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Anton Khirnov Jan. 24, 2021, 1:12 p.m. UTC | #1
Quoting Michael Niedermayer (2021-01-23 23:10:51)
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavutil/common.h | 8 ++++++++

This is a public header, so a minor bump+APIchanges entry are needed.

(ideally we'd also rename those to use the AV prefix, but that is for
later)
Michael Niedermayer Jan. 26, 2021, 4:12 p.m. UTC | #2
On Sun, Jan 24, 2021 at 02:12:35PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-01-23 23:10:51)
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavutil/common.h | 8 ++++++++
> 
> This is a public header, so a minor bump+APIchanges entry are needed.

will apply with this

thx

[...]
diff mbox series

Patch

diff --git a/libavutil/common.h b/libavutil/common.h
index b9fbcc4d60..a60a558b1d 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -80,6 +80,14 @@ 
  */
 #define FFNABS(a) ((a) <= 0 ? (a) : (-(a)))
 
+/**
+ * Unsigned Absolute value.
+ * This takes the absolute value of a signed int and returns it as a unsigned.
+ * This also works with INT_MIN which would otherwise not be representable
+ * As with many macros, this evaluates its argument twice.
+ */
+#define FFABSU(a) ((a) <= 0 ? -(unsigned)(a) : (unsigned)(a))
+
 /**
  * Comparator.
  * For two numerical expressions x and y, gives 1 if x > y, -1 if x < y, and 0