[FFmpeg-devel] [PATCH] [libavutil] Add saturated add/sub operations for int64_t.

Michael Niedermayer michael at niedermayer.cc
Fri May 1 22:52:48 EEST 2020


On Thu, Apr 30, 2020 at 05:39:43PM -0700, Dale Curtis wrote:
> On Thu, Apr 30, 2020 at 5:21 PM James Almer <jamrial at gmail.com> wrote:
> 
> > On 4/30/2020 7:19 PM, Dale Curtis wrote:
> > > Many places are using their own custom code for handling overflow
> > > around timestamps or other int64_t values. There are enough of these
> > > now that having some common saturated math functions seems sound.
> > >
> > > This adds implementations that just use the builtin functions for
> > > recent gcc, clang when available or implements its own version for
> > > older compilers.
> >
> > These look like 64 bit versions of av_sat_add32 and av_sat_sub32, from
> > common.h, so you should probably add them there and rename them
> > accordingly.
> >
> >
> Ah! I was looking for those, but missed them. Thanks. Done.

one disadvantage the av_sat* functions have is the lack of inexact detection

In addition to av_sat*
In situations where its better to fail than to clip, something that
emulates what (+-Inf/)NaN is for float may make sense.
That would allow to simply check after a computation if any inexactness
occured

Such a thing could be usefull in situations where a exact value or an
error is wanted.

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200501/88b6f320/attachment.sig>


More information about the ffmpeg-devel mailing list