| jaulib v1.4.0-2-g788cf73
    Jau Support Library (C++, Java, ..) | 
Integral integer types and arithmetic. More...
| Namespaces | |
| namespace | jau::int_literals | 
| Classes | |
| class | jau::mp::BigInt | 
| Arbitrary precision integer type.  More... | |
| struct | jau::float_bytes< bytesize > | 
| struct | jau::float_bytes< sizeof(double)> | 
| struct | jau::float_bytes< sizeof(float)> | 
| struct | jau::float_bytes< sizeof(long double)> | 
| class | jau::int_ctti | 
| struct | jau::sint_bytes< bytesize > | 
| struct | jau::sint_bytes< 4 > | 
| struct | jau::sint_bytes< 8 > | 
| struct | jau::uint128dp_t | 
| A 128-bit packed uint8_t data array.  More... | |
| struct | jau::uint192dp_t | 
| A 196-bit packed uint8_t data array.  More... | |
| struct | jau::uint256dp_t | 
| A 256-bit packed uint8_t data array.  More... | |
| struct | jau::uint_bytes< bytesize > | 
| struct | jau::uint_bytes< 4 > | 
| struct | jau::uint_bytes< 8 > | 
| Typedefs | |
| template<int bytesize> | |
| using | jau::float_bytes_t = typename float_bytes<bytesize>::type | 
| Alias template for float_bytes. | |
| typedef uint_fast32_t | jau::nsize_t | 
| Natural 'size_t' alternative using uint_fast32_tas its natural sized type. | |
| template<int bytesize> | |
| using | jau::sint_bytes_t = typename sint_bytes<bytesize>::type | 
| Alias template for sint_bytes. | |
| typedef int_fast32_t | jau::snsize_t | 
| Natural 'ssize_t' alternative using int_fast32_tas its natural sized type. | |
| template<int bytesize> | |
| using | jau::uint_bytes_t = typename uint_bytes<bytesize>::type | 
| Alias template for uint_bytes. | |
| Functions | |
| mp::BigInt | jau::abs (const mp::BigInt &x) noexcept | 
| template<jau::req::signed_arithmetic T> | |
| constexpr T | jau::abs (const T x) noexcept | 
| Returns the absolute value of an arithmetic number (w/ branching) in O(1) | |
| template<std::integral T> | |
| 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. | |
| template<jau::req::unsigned_integral T> | |
| constexpr T | jau::bit_ceil (const T n) noexcept | 
| If the given nis not is_power_of_2() return next_power_of_2(), otherwise returnnunchanged. | |
| template<jau::req::unsigned_integral T> | |
| constexpr size_t | jau::bit_count (T n) noexcept | 
| Returns the number of set bits within given unsigned integral. | |
| const mp::BigInt & | jau::clamp (const mp::BigInt &x, const mp::BigInt &min_val, const mp::BigInt &max_val) noexcept | 
| template<jau::req::arithmetic T> | |
| constexpr T | jau::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 (w/ branching) in O(1). | |
| mp::BigInt & | jau::clamp (mp::BigInt &x, mp::BigInt &min_val, mp::BigInt &max_val) noexcept | 
| void | jau::clear_bit_uint32 (const uint8_t nr, uint32_t &mask) | 
| void | jau::clear_bit_uint64 (const uint8_t nr, uint64_t &mask) | 
| template<jau::req::unsigned_integral T> | |
| constexpr size_t | jau::digits (const T x, const nsize_t radix) noexcept | 
| Returns the number of digits of the given unsigned integral value number and the given radix. | |
| template<std::integral T> | |
| constexpr size_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>(). | |
| template<std::integral T> | |
| constexpr size_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>(). | |
| template<std::integral T> | |
| constexpr bool | jau::equals (const T &a, const T &b) noexcept | 
| Returns true if both values are equal. | |
| mp::BigInt | jau::gcd (const mp::BigInt &a, const mp::BigInt &b) noexcept | 
| template<jau::req::signed_integral T> | |
| 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. | |
| consteval_cxx20 bool | jau::has_builtin_add_overflow () noexcept | 
| Query whether __builtin_add_overflowis available via__has_builtin(__builtin_add_overflow). | |
| consteval_cxx20 bool | jau::has_builtin_mul_overflow () noexcept | 
| Query whether __builtin_mul_overflowis available via__has_builtin(__builtin_mul_overflow). | |
| consteval_cxx20 bool | jau::has_builtin_sub_overflow () noexcept | 
| Query whether __builtin_sub_overflowis available via__has_builtin(__builtin_sub_overflow). | |
| template<jau::req::unsigned_integral T> | |
| constexpr nsize_t | jau::high_bit (T x) | 
| Return the index of the highest set bit w/ branching (loop) in O(n/2). | |
| template<jau::req::arithmetic T> | |
| bool | jau::in_range (const T &a, const T &b, const T &range) | 
| base_math: arithmetic types, i.e. | |
| template<jau::req::signed_arithmetic T> | |
| constexpr T | jau::invert_sign (const T x) noexcept | 
| Safely inverts the sign of an arithmetic number w/ branching in O(1) | |
| template<jau::req::unsigned_integral T> | |
| constexpr bool | jau::is_power_of_2 (const T x) noexcept | 
| Power of 2 test in O(1), i.e. | |
| template<std::integral T> | |
| constexpr bool | jau::is_zero (const T &a) noexcept | 
| base_math: arithmetic types, i.e. | |
| template<std::integral T> | |
| 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. | |
| constexpr size_t | jau::log2_byteshift (const size_t bytesize) noexcept | 
| Returns log2(bytesize*8), e.g. | |
| const mp::BigInt & | jau::max (const mp::BigInt &x, const mp::BigInt &y) noexcept | 
| template<jau::req::arithmetic T> | |
| constexpr T | jau::max (const T x, const T y) noexcept | 
| Returns the maximum of two integrals (w/ branching) in O(1) | |
| mp::BigInt & | jau::max (mp::BigInt &x, mp::BigInt &y) noexcept | 
| uint128dp_t | jau::merge_uint128 (uint16_t const uuid16, uint128dp_t const &base_uuid, nsize_t const uuid16_le_octet_index) | 
| Merge the given 'uuid16' into a 'base_uuid' copy at the given little endian 'uuid16_le_octet_index' position. | |
| uint128dp_t | jau::merge_uint128 (uint32_t const uuid32, uint128dp_t const &base_uuid, nsize_t const uuid32_le_octet_index) | 
| Merge the given 'uuid32' into a 'base_uuid' copy at the given little endian 'uuid32_le_octet_index' position. | |
| const mp::BigInt & | jau::min (const mp::BigInt &x, const mp::BigInt &y) noexcept | 
| template<jau::req::arithmetic T> | |
| constexpr T | jau::min (const T x, const T y) noexcept | 
| Returns the minimum of two integrals (w/ branching) in O(1) | |
| mp::BigInt & | jau::min (mp::BigInt &x, mp::BigInt &y) noexcept | 
| template<std::integral T> | |
| 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. | |
| mp::BigInt | jau::pow (mp::BigInt b, const mp::BigInt &e) | 
| template<jau::req::unsigned_integral T, jau::req::unsigned_integral U> | |
| constexpr T | jau::round_down (T n, U align_to) | 
| Round down w/ branching in O(1) | |
| template<jau::req::unsigned_integral T, jau::req::unsigned_integral U> | |
| constexpr T | jau::round_up (const T n, const U align_to) | 
| Round up w/ branching in O(1) | |
| void | jau::set_bit_uint32 (const uint8_t nr, uint32_t &mask) | 
| void | jau::set_bit_uint64 (const uint8_t nr, uint64_t &mask) | 
| template<jau::req::signed_arithmetic T> | |
| constexpr int | jau::sign (const T x) noexcept | 
| Returns the value of the sign function (w/o branching ?) in O(1). | |
| template<std::integral T> | |
| 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. | |
| uint32_t | jau::test_bit_uint32 (const uint8_t nr, const uint32_t mask) | 
| uint64_t | jau::test_bit_uint64 (const uint8_t nr, const uint64_t mask) | 
Integral integer types and arithmetic.
Further support is coming from Byte Utilities and meta-group Math Support
| typedef uint_fast32_t jau::nsize_t | 
Natural 'size_t' alternative using uint_fast32_t as its natural sized type. 
The leading 'n' stands for natural.
This is a compromise to indicate intend, but to avoid handling a multiple sized size_t footprint where not desired. 
Definition at line 55 of file int_types.hpp.
| typedef int_fast32_t jau::snsize_t | 
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type. 
The leading 'n' stands for natural.
This is a compromise to indicate intend, but to avoid handling a multiple sized ssize_t footprint where not desired. 
Definition at line 67 of file int_types.hpp.
| using jau::uint_bytes_t = typename uint_bytes<bytesize>::type | 
Alias template for uint_bytes.
Definition at line 79 of file int_types.hpp.
| using jau::sint_bytes_t = typename sint_bytes<bytesize>::type | 
Alias template for sint_bytes.
Definition at line 89 of file int_types.hpp.
| using jau::float_bytes_t = typename float_bytes<bytesize>::type | 
Alias template for float_bytes.
Definition at line 97 of file int_types.hpp.
| bool jau::in_range | ( | const T & | a, | 
| const T & | b, | ||
| const T & | range ) | 
base_math: arithmetic types, i.e.
integral + floating point types int_math: integral types float_math: floating point types Returns true, if both integer point values differ less than the given range.
| T | an arithmetic type | 
| a | value to compare | 
| b | value to compare | 
| range | the maximum difference both values may differ | 
Definition at line 61 of file base_math.hpp.
| 
 | constexprnoexcept | 
Returns the value of the sign function (w/o branching ?) in O(1).
-1 for x < 0 0 for x = 0 1 for x > 0
Implementation is type safe.
Branching may occur due to relational operator.
| T | an arithmetic number type | 
| x | the arithmetic number | 
Definition at line 81 of file base_math.hpp.
| 
 | constexprnoexcept | 
Safely inverts the sign of an arithmetic number w/ branching in O(1)
Implementation takes special care to have T_MIN, i.e. std::numeric_limits<T>::min(), converted to T_MAX, i.e. std::numeric_limits<T>::max().
 This is necessary since T_MAX < | -T_MIN | and the result would not fit in the return type T otherwise.
Hence for the extreme minimum case:
jau::invert_sign<int32_t>(INT32_MIN) = | INT32_MIN | - 1 = INT32_MAX
Otherwise with x < 0:
jau::invert_sign<int32_t>(x) = | x | = -x
and x >= 0:
jau::invert_sign<int32_t>(x) = -x
| T | an unsigned arithmetic number type | 
| x | the number | 
Definition at line 119 of file base_math.hpp.
| 
 | constexprnoexcept | 
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
This implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
| T | an arithmetic number type | 
| x | the number | 
Definition at line 144 of file base_math.hpp.
| 
 | constexprnoexcept | 
Returns the minimum of two integrals (w/ branching) in O(1)
| T | an arithmetic number type | 
| x | one number | 
| x | the other number | 
Definition at line 163 of file base_math.hpp.
| 
 | constexprnoexcept | 
Returns the maximum of two integrals (w/ branching) in O(1)
| T | an arithmetic number type | 
| x | one number | 
| x | the other number | 
Definition at line 176 of file base_math.hpp.
| 
 | constexprnoexcept | 
Returns constrained integral value to lie between given min- and maximum value (w/ branching) in O(1).
Implementation returns min(max(x, min_val), max_val), analog to GLSL's clamp()
| T | an arithmetic number type | 
| x | one number | 
| min_val | the minimum limes, inclusive | 
| max_val | the maximum limes, inclusive | 
Definition at line 192 of file base_math.hpp.
| 
 | inline | 
Definition at line 608 of file basic_types.hpp.
| 
 | inline | 
Definition at line 614 of file basic_types.hpp.
| 
 | inline | 
Definition at line 620 of file basic_types.hpp.
| 
 | inline | 
Definition at line 626 of file basic_types.hpp.
| 
 | inline | 
Definition at line 632 of file basic_types.hpp.
| 
 | inline | 
Definition at line 638 of file basic_types.hpp.
| uint128dp_t jau::merge_uint128 | ( | uint16_t const | uuid16, | 
| uint128dp_t const & | base_uuid, | ||
| nsize_t const | uuid16_le_octet_index ) | 
Merge the given 'uuid16' into a 'base_uuid' copy at the given little endian 'uuid16_le_octet_index' position.
The given 'uuid16' value will be added with the 'base_uuid' copy at the given position.
base_uuid: 00000000-0000-1000-8000-00805F9B34FB
   uuid16: DCBA
uuid16_le_octet_index: 12
   result: 0000DCBA-0000-1000-8000-00805F9B34FB
LE: low-mem - FB349B5F8000-0080-0010-0000-ABCD0000 - high-mem
                                          ^ index 12
LE: uuid16 -> value.data[12+13]
BE: low-mem - 0000DCBA-0000-1000-8000-00805F9B34FB - high-mem
                  ^ index 2
BE: uuid16 -> value.data[2+3]
 
Definition at line 491 of file basic_types.cpp.
| uint128dp_t jau::merge_uint128 | ( | uint32_t const | uuid32, | 
| uint128dp_t const & | base_uuid, | ||
| nsize_t const | uuid32_le_octet_index ) | 
Merge the given 'uuid32' into a 'base_uuid' copy at the given little endian 'uuid32_le_octet_index' position.
The given 'uuid32' value will be added with the 'base_uuid' copy at the given position.
base_uuid: 00000000-0000-1000-8000-00805F9B34FB
   uuid32: 87654321
uuid32_le_octet_index: 12
   result: 87654321-0000-1000-8000-00805F9B34FB
LE: low-mem - FB349B5F8000-0080-0010-0000-12345678 - high-mem
                                          ^ index 12
LE: uuid32 -> value.data[12..15]
BE: low-mem - 87654321-0000-1000-8000-00805F9B34FB - high-mem
              ^ index 0
BE: uuid32 -> value.data[0..3]
 
Definition at line 525 of file basic_types.cpp.
| 
 | constexprnoexcept | 
base_math: arithmetic types, i.e.
integral + floating point types int_math: integral types float_math: floating point types Returns true of the given integer value is zero.
Definition at line 57 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns true if both values are equal.
| T | an integral type | 
| a | value to compare | 
| b | value to compare | 
Definition at line 69 of file int_math.hpp.
| 
 | constexpr | 
Round up w/ branching in O(1)
| T | an unsigned integral number type | 
| U | an unsigned integral number type | 
| n | to be aligned number | 
| align_to | alignment boundary, must not be 0 | 
Definition at line 96 of file int_math.hpp.
| 
 | constexpr | 
Round down w/ branching in O(1)
| T | an unsigned integral number type | 
| U | an unsigned integral number type | 
| n | to be aligned number | 
| align_to | alignment boundary | 
Definition at line 116 of file int_math.hpp.
| 
 | constexprnoexcept | 
Power of 2 test in O(1), i.e.
test whether a single bit is set
Uses either
| T | an unsigned integral number type | 
| x | the unsigned integral number | 
Definition at line 134 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns log2(bytesize*8), e.g.
to bit-shift whole byte values
If bytesize is not of power2, zero is returned.
| bytesize | number of bytes | 
Definition at line 150 of file int_math.hpp.
| 
 | constexprnoexcept | 
If the given n is not is_power_of_2() return next_power_of_2(), otherwise return n unchanged. 
Uses either
Definition at line 186 of file int_math.hpp.
| 
 | constexpr | 
Return the index of the highest set bit w/ branching (loop) in O(n/2).
| T | an unsigned integral number type | 
| x | value | 
Definition at line 203 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns the number of set bits within given unsigned integral.
| T | an unsigned integral number type | 
| n | value | 
Definition at line 220 of file int_math.hpp.
| 
 | noexcept | 
Query whether __builtin_add_overflow is available via __has_builtin(__builtin_add_overflow). 
Definition at line 228 of file int_math.hpp.
| 
 | noexcept | 
Query whether __builtin_sub_overflow is available via __has_builtin(__builtin_sub_overflow). 
Definition at line 239 of file int_math.hpp.
| 
 | noexcept | 
Query whether __builtin_mul_overflow is available via __has_builtin(__builtin_mul_overflow). 
Definition at line 250 of file int_math.hpp.
| 
 | constexprnoexcept | 
Integer overflow aware addition returning true if overflow occurred, otherwise false having the result stored in res.
Implementation uses Integer Overflow Builtins if available, otherwise its own implementation.
| T | an integral integer type | 
param a operand a
| b | operand b | 
| res | storage for result | 
Definition at line 273 of file int_math.hpp.
| 
 | constexprnoexcept | 
Integer overflow aware subtraction returning true if overflow occurred, otherwise false having the result stored in res.
Implementation uses Integer Overflow Builtins if available, otherwise its own implementation.
| T | an integral integer type | 
param a operand a
| b | operand b | 
| res | storage for result | 
Definition at line 304 of file int_math.hpp.
| 
 | constexprnoexcept | 
Integer overflow aware multiplication returning true if overflow occurred, otherwise false having the result stored in res.
Implementation uses Integer Overflow Builtins if available, otherwise its own implementation.
| T | an integral integer type | 
param a operand a
| b | operand b | 
| res | storage for result | 
Definition at line 335 of file int_math.hpp.
| 
 | constexprnoexcept | 
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.
Returns zero if a and b is zero.
Note implementation uses modulo operator (a/b)*b + a % b = a, i.e. remainder of the integer division - hence implementation uses abs(a) % abs(b) in case the integral T is a signed type (dropped for unsigned).
Implementation is similar to std::gcd(), however, it uses a fixed common type T and a while loop instead of compile time evaluation via recursion.
| T | integral type | 
param a integral value a
| b | integral value b | 
Definition at line 370 of file int_math.hpp.
| 
 | constexprnoexcept | 
Integer overflow aware calculation of least common multiple (LCM) following Euclid's algorithm from Euclid's Elements ~300 BC.
| T | integral type | 
param result storage for lcm result: zero if a and b are zero, otherwise lcm of a and b
| a | integral value a | 
| b | integral value b | 
Definition at line 401 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns the number of decimal digits of the given integral value number using std::log10<T>().
 If sign_is_digit == true (default), treats a potential negative sign as a digit. 
x < 0: 1 + (int) ( log10( -x ) ) + ( sign_is_digit ? 1 : 0 ) x = 0: 1 x > 0: 1 + (int) ( log10( x ) )
Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
Convenience method, reusing precomputed sign of value to avoid redundant computations.
| T | an integral integer type | 
| x | the integral integer | 
| x_sign | the pre-determined sign of the given value x | 
| sign_is_digit | if true and value is negative, adds one to result for sign. Defaults to true. | 
Definition at line 436 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns the number of decimal digits of the given integral value number using std::log10<T>().
If sign_is_digit == true (default), treats a potential negative sign as a digit.
x < 0: 1 + (int) ( log10( -x ) ) + ( sign_is_digit ? 1 : 0 ) x = 0: 1 x > 0: 1 + (int) ( log10( x ) )
Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
| T | an integral integer type | 
| x | the integral integer | 
| sign_is_digit | if true and value is negative, adds one to result for sign. Defaults to true. | 
Definition at line 462 of file int_math.hpp.
| 
 | constexprnoexcept | 
Returns the number of digits of the given unsigned integral value number and the given radix.
| T | an integral unsigned integer type | 
| x | the integral integer | 
| radix | base of the number system, e.g. 2 binary, 8 octal, 10 decimal, 16 hexadecimal, .. | 
Definition at line 476 of file int_math.hpp.
| 
 | inlinenoexcept | 
Definition at line 1565 of file big_int.hpp.
| 
 | inline | 
| 
 | inlinenoexcept | 
Definition at line 1568 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1571 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1574 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1578 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1581 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1584 of file big_int.hpp.
| 
 | inlinenoexcept | 
Definition at line 1588 of file big_int.hpp.