AMInteger  201909
String localization library
Functions
AMInteger.h File Reference
#include <type_traits>
#include <limits>
Include dependency graph for AMInteger.h:

Go to the source code of this file.

Functions

template<typename TIntType >
TIntType AMCore::AMIntegerHi (TIntType x)
 Safe integer operations with overflow detection. More...
 
template<typename TIntType >
TIntType AMCore::AMIntegerLo (TIntType x)
 Low bits (a half) of argument. More...
 
template<typename TIntType >
bool AMCore::AMIntegerMultiply (TIntType a, TIntType b, TIntType &result)
 Safe multiply with overflow detection. More...
 
template<typename TIntType >
bool AMCore::AMIntegerAdd (TIntType a, TIntType b, TIntType &result)
 Safe addition with overflow detection. More...
 

Detailed Description

Safe integer operations with overflow detection

Author
Zdeněk Skulínek <me@zdenekskulinek.cz>

Function Documentation

◆ AMIntegerAdd()

template<typename TIntType >
bool AMCore::AMIntegerAdd ( TIntType  a,
TIntType  b,
TIntType &  result 
)

Safe addition with overflow detection.

Parameters
afirst addend
bsecond addend
resultreference to result
Returns
true if success, false if overflow
Exceptions
Thisfunction will not throw an exception.

References AMCore::AMIntegerAdd(), AMCore::AMIntegerHi(), and AMCore::AMIntegerLo().

Referenced by AMCore::AMIntegerAdd().

◆ AMIntegerHi()

template<typename TIntType >
TIntType AMCore::AMIntegerHi ( TIntType  x)

Safe integer operations with overflow detection.

All function have TIntType template argument. The argument may by any integral type.

High bits (a half) of argument

Parameters
x
Exceptions
Thisfunction will not throw an exception.

References AMCore::AMIntegerHi().

Referenced by AMCore::AMIntegerAdd(), AMCore::AMIntegerHi(), and AMCore::AMIntegerMultiply().

◆ AMIntegerLo()

template<typename TIntType >
TIntType AMCore::AMIntegerLo ( TIntType  x)

Low bits (a half) of argument.

Parameters
x
Exceptions
Thisfunction will not throw an exception.

References AMCore::AMIntegerLo().

Referenced by AMCore::AMIntegerAdd(), AMCore::AMIntegerLo(), and AMCore::AMIntegerMultiply().

◆ AMIntegerMultiply()

template<typename TIntType >
bool AMCore::AMIntegerMultiply ( TIntType  a,
TIntType  b,
TIntType &  result 
)

Safe multiply with overflow detection.

Parameters
afirst multiplicand
bsecond multiplicand
resultreference to result
Returns
true if success, false if overflow
Exceptions
Thisfunction will not throw an exception.

References AMCore::AMIntegerHi(), AMCore::AMIntegerLo(), and AMCore::AMIntegerMultiply().

Referenced by AMCore::AMIntegerMultiply().