C++ Reference: saturated_arithmetic

This documentation is automatically generated.




   ---------- Overflow utility functions ----------

Implement two's complement addition and subtraction on int64s.

The C and C++ standards specify that the overflow of signed integers is undefined. This is because of the different possible representations that may be used for signed integers (one's complement, two's complement, sign and magnitude). Such overflows are detected by Address Sanitizer with
   -fsanitize=signed-integer-overflow.

Simple, portable overflow detection on current machines relies on

these two functions. For example, if the sign of the sum of two positive integers is negative, there has been an overflow.

Note that the static assert will break if the code is compiled on machines which do not use two's complement.
Function Type Arguments Comments
AddHadOverflow

Return type: inline bool

Arguments: int64 x, int64 y, int64 sum

AddOverflows

Return type: inline bool

Arguments: int64 x, int64 y

CapAdd

Return type: inline int64

Arguments: int64 x, int64 y

CapAddFast

Return type: inline int64

Arguments: int64 x, int64 y

CapAddGeneric

Return type: inline int64

Arguments: int64 x, int64 y

CapOpp

Return type: inline int64

Arguments: int64 v

CapProd

Return type: inline int64

Arguments: int64 x, int64 y

CapProdFast

Return type: inline int64

Arguments: int64 x, int64 y

CapProdGeneric

Return type: inline int64

Arguments: int64 x, int64 y

CapSub

Return type: inline int64

Arguments: int64 x, int64 y

CapSubFast

Return type: inline int64

Arguments: int64 x, int64 y

CapSubGeneric

Return type: inline int64

Arguments: int64 x, int64 y

CapWithSignOf

Return type: inline int64

Arguments: int64 x

SafeAddInto

Return type: bool

Arguments: IntegerType a, IntegerType* b

SubHadOverflow

Return type: inline bool

Arguments: int64 x, int64 y, int64 diff

SubOverflows

Return type: inline int64

Arguments: int64 x, int64 y

TwosComplementAddition

Return type: inline int64

Arguments: int64 x, int64 y

TwosComplementSubtraction

Return type: inline int64

Arguments: int64 x, int64 y

uint_abs

Return type: inline uint64

Arguments: int64 n

Send feedback about...