Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Namespaces | Functions
int_math_ct.hpp File Reference
#include <cstdint>
#include <climits>
#include <jau/int_types.hpp>
#include <jau/cpp_pragma.hpp>
Include dependency graph for int_math_ct.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.
 

Functions

template<typename T , std::enable_if_t< std::is_arithmetic_v< T > &&std::is_integral_v< T > &&!std::is_unsigned_v< T >, bool > = true>
constexpr T jau::ct_abs (const T x) noexcept
 Returns the absolute value of an arithmetic number (w/o branching) in O(1) and constant time (CT), while ct_abs(INT_MIN) is undefined behavior (UB) instead of being mapped correctly to INT_MAX like jau::abs() does, see above. More...
 
constexpr uint32_t jau::ct_bit_count (uint32_t n) noexcept
 Returns the number of set bits within given 32bit integer (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr T jau::ct_clamp (const T x, const T min_val, const T max_val) noexcept
 Returns constrained integral value to lie between given min- and maximum value for MIN <= x - y <= MAX (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T >, bool > = true>
constexpr T jau::ct_expand_top_bit (T x)
 Returns ~0 (2-complement) if top bit of arg is set, otherwise 0 (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T >, bool > = true>
constexpr T jau::ct_is_zero (T x)
 Returns ~0 (2-complement) if arg is zero, otherwise 0 (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_unsigned_v< T >, bool > = true>
constexpr T jau::ct_masked_merge (T mask, T a_if_masked, T b_if_unmasked)
 Returns merged a_if_masked bits selected by mask 1 bits and b_if_unmasked bits selected by mask 0 bits (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr T jau::ct_max (const T x, const T y) noexcept
 Returns the maximum of two integrals for MIN <= x - y <= MAX (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr T jau::ct_min (const T x, const T y) noexcept
 Returns the minimum of two integrals for MIN <= x - y <= MAX (w/o branching) in O(1) and constant time (CT). More...
 
constexpr uint32_t jau::ct_next_power_of_2 (uint32_t n)
 Returns the next higher power of 2 of given unsigned 32-bit n (w/o branching) in O(1) and constant time (CT). More...
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr int jau::ct_sign (const T x) noexcept
 Returns the value of the sign function (w/o branching) in O(1) and constant time (CT) More...