MIP_SDK  v3.0.0-187-g93c7302
MicroStrain Communications Library for embedded systems
Classes | Namespaces | Functions
saturating_math.hpp File Reference
#include <limits>
#include <type_traits>
#include <numeric>

Go to the source code of this file.

Classes

class  microstrain::SaturatingInt< T >
 A class representing an integer that saturates instead of overflowing. More...
 

Namespaces

 microstrain
 

Functions

template<class T >
constexpr T microstrain::add_sat (T x, T y) noexcept
 
template<class T >
constexpr T microstrain::sub_sat (T x, T y) noexcept
 
template<class T , class U >
constexpr T microstrain::saturate_cast (U x) noexcept
 Convert an integral value to a different integral type while preventing overflow. More...
 
template<class T , class U >
constexpr void microstrain::assign_sat (T &destination, U value)
 Assign an integral value to a destination variable, clamping its value to the range of the destination type. More...
 
template<class T , class U >
constexpr T & microstrain::accum_sat (T &counter, U amount)
 Add a value to an accumulator and prevent it from overflowing. More...
 
template<class T , class U >
constexpr T & microstrain::reduce_sat (T &counter, U amount)
 Subtract a value from an accumulator and prevent it from overflowing. More...