Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Namespaces | Macros | Functions
int_math.hpp File Reference
#include <cstdint>
#include <cmath>
#include <climits>
#include <jau/base_math.hpp>
#include <jau/int_math_ct.hpp>
Include dependency graph for int_math.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  jau
 __pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 

Macros

#define JAU_USE_BUILDIN_OVERFLOW   1
 

Functions

template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr bool jau::add_overflow (const T a, const T b, T &res) noexcept
 Integer overflow aware addition returning true if overflow occurred, otherwise false having the result stored in res. More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr nsize_t jau::digits10 (const T x, const bool sign_is_digit=true) noexcept
 Returns the number of decimal digits of the given integral value number using std::log10<T>(). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr nsize_t jau::digits10 (const T x, const snsize_t x_sign, const bool sign_is_digit=true) noexcept
 Returns the number of decimal digits of the given integral value number using std::log10<T>(). More...
 
template<class T >
std::enable_if< std::is_integral_v< T >, bool >::type constexpr jau::equals (const T &a, const T &b) noexcept
 Returns true if both values are equal. More...
 
template<class T >
std::enable_if< std::is_integral_v< T >, bool >::type constexpr jau::equals (const T &a, const T &b, const T &allowed_deviation) noexcept
 Returns true if both values are equal, i.e. More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&!std::is_unsigned_v< T >, bool > = true>
constexpr T jau::gcd (T a, T b) noexcept
 Returns the greatest common divisor (GCD) of the two given integer values following Euclid's algorithm from Euclid's Elements ~300 BC, using the absolute positive value of given integers. More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T >, bool > = true>
constexpr nsize_t jau::high_bit (T x)
 Return the index of the highest set bit w/ branching (loop) in O(n), actually O(n/2). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T >, bool > = true>
constexpr bool jau::is_power_of_2 (const T x) noexcept
 Power of 2 test (w/o branching ?) in O(1) More...
 
template<class T >
std::enable_if< std::is_integral_v< T >, bool >::type constexpr jau::is_zero (const T &a) noexcept
 base_math: arithmetic types, i.e. More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr bool jau::lcm_overflow (const T a, const T b, T &result) noexcept
 Integer overflow aware calculation of least common multiple (LCM) following Euclid's algorithm from Euclid's Elements ~300 BC. More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr bool jau::mul_overflow (const T a, const T b, T &res) noexcept
 Integer overflow aware multiplication returning true if overflow occurred, otherwise false having the result stored in res. More...
 
template<typename T , typename U , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T > &&std::is_integral_v< U > &&std::is_unsigned_v< U >, bool > = true>
constexpr T jau::round_down (T n, U align_to)
 Round down w/ branching in O(1) More...
 
constexpr uint32_t jau::round_to_power_of_2 (const uint32_t n)
 If the given n is not is_power_of_2() return next_power_of_2(), otherwise return n unchanged. More...
 
template<typename T , typename U , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T > &&std::is_integral_v< U > &&std::is_unsigned_v< U >, bool > = true>
constexpr T jau::round_up (const T n, const U align_to)
 Round up w/ branching in O(1) More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr bool jau::sub_overflow (const T a, const T b, T &res) noexcept
 Integer overflow aware subtraction returning true if overflow occurred, otherwise false having the result stored in res. More...
 

Macro Definition Documentation

◆ JAU_USE_BUILDIN_OVERFLOW

#define JAU_USE_BUILDIN_OVERFLOW   1

Definition at line 37 of file int_math.hpp.