Bitcoin Core 28.99.0
P2P Digital Currency
Functions
overflow.h File Reference
#include <climits>
#include <concepts>
#include <limits>
#include <optional>
#include <type_traits>
Include dependency graph for overflow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<class T >
bool AdditionOverflow (const T i, const T j) noexcept
 
template<class T >
std::optional< T > CheckedAdd (const T i, const T j) noexcept
 
template<class T >
SaturatingAdd (const T i, const T j) noexcept
 
template<std::integral T>
constexpr std::optional< T > CheckedLeftShift (T input, unsigned shift) noexcept
 Left bit shift with overflow checking. More...
 
template<std::integral T>
constexpr T SaturatingLeftShift (T input, unsigned shift) noexcept
 Left bit shift with safe minimum and maximum values. More...
 

Function Documentation

◆ AdditionOverflow()

template<class T >
bool AdditionOverflow ( const T  i,
const T  j 
)
noexcept

Definition at line 15 of file overflow.h.

Here is the caller graph for this function:

◆ CheckedAdd()

template<class T >
std::optional< T > CheckedAdd ( const T  i,
const T  j 
)
noexcept

Definition at line 26 of file overflow.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckedLeftShift()

template<std::integral T>
constexpr std::optional< T > CheckedLeftShift ( input,
unsigned  shift 
)
constexprnoexcept

Left bit shift with overflow checking.

Parameters
inputThe input value to be left shifted.
shiftThe number of bits to left shift.
Returns
(input * 2^shift) or nullopt if it would not fit in the return type.

Definition at line 59 of file overflow.h.

Here is the caller graph for this function:

◆ SaturatingAdd()

template<class T >
T SaturatingAdd ( const T  i,
const T  j 
)
noexcept

Definition at line 35 of file overflow.h.

Here is the caller graph for this function:

◆ SaturatingLeftShift()

template<std::integral T>
constexpr T SaturatingLeftShift ( input,
unsigned  shift 
)
constexprnoexcept

Left bit shift with safe minimum and maximum values.

Parameters
inputThe input value to be left shifted.
shiftThe number of bits to left shift.
Returns
(input * 2^shift) clamped to fit between the lowest and highest representable values of the type T.

Definition at line 78 of file overflow.h.

Here is the call graph for this function: