|
jaulib v1.4.1
Jau Support Library (C++, Java, ..)
|
#include <bit>#include <climits>#include <cmath>#include <concepts>#include <jau/base_math.hpp>#include <jau/int_math_ct.hpp>#include <jau/type_concepts.hpp>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<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 n is not is_power_of_2() return next_power_of_2(), otherwise return n unchanged. | |
| 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. | |
| 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. | |
| template<std::floating_point T> | |
| constexpr bool | jau::equals (const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept |
| Returns true if both values are equal, i.e. | |
| 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_overflow is available via __has_builtin(__builtin_add_overflow). | |
| consteval_cxx20 bool | jau::has_builtin_mul_overflow () noexcept |
Query whether __builtin_mul_overflow is available via __has_builtin(__builtin_mul_overflow). | |
| consteval_cxx20 bool | jau::has_builtin_sub_overflow () noexcept |
Query whether __builtin_sub_overflow is 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::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. | |
| 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. | |
| 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) | |
| 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. | |