Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Namespaces | Typedefs | Functions | Variables
float_math.hpp File Reference
#include <cmath>
#include <climits>
#include <type_traits>
#include <algorithm>
#include <jau/base_math.hpp>
#include <jau/string_util.hpp>
Include dependency graph for float_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.
 

Typedefs

typedef jau::uint_bytes< sizeof(double)>::type jau::double_uint_t
 
typedef jau::uint_bytes< sizeof(float)>::type jau::float_uint_t
 

Functions

template<typename T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
constexpr T jau::adeg_to_rad (const T arc_degree) noexcept
 Converts arc-degree to radians. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type jau::almost_equal (const T &a, const T &b, int ulp=1, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true, if both floating point values are equal in the sense that their potential difference is less or equal epsilon * |a+b| * ulp, where |a+b| scales epsilon to the magnitude of used values. More...
 
constexpr uint64_t jau::bit_value (const double a) noexcept
 Returns the unsigned integer representation according to IEEE 754 (IEC 559) double floating-point bit layout. More...
 
constexpr uint32_t jau::bit_value (const float a) noexcept
 Returns the unsigned integer representation according to IEEE 754 (IEC 559) single floating-point bit layout. More...
 
constexpr uint64_t jau::bit_value_raw (const double a) noexcept
 Returns the unsigned integer representation according to IEEE 754 (IEC 559) double floating-point bit layout. More...
 
constexpr uint32_t jau::bit_value_raw (const float a) noexcept
 Returns the unsigned integer representation according to IEEE 754 (IEC 559) single floating-point bit layout. More...
 
template<class T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
jau::uint_bytes< sizeof(T)>::type jau::bit_value_raw (const T a) noexcept
 Returns the unsigned integer representation according to IEEE 754 (IEC 559) floating-point bit layout. More...
 
template<class T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
constexpr int jau::compare (const T a, const T b) noexcept
 Returns -1, 0 or 1 if a is less, equal or greater than b, disregarding epsilon but considering NaN, -Inf and +Inf. More...
 
template<class T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
constexpr int jau::compare (const T a, const T b, const T epsilon) noexcept
 Returns -1, 0 or 1 if a is less, equal or greater than b, considering epsilon and NaN, -Inf and +Inf. More...
 
constexpr double jau::double_value (const uint64_t a) noexcept
 Converting IEEE 754 (IEC 559) double floating-point bit layout to double, see bit_value() More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr 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. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::equals (const T &a, const T &b, int ulp, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true, if both floating point values are equal in the sense that their potential difference is less or equal epsilon * ulp. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::equals2 (const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true if both values are equal, i.e. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::equals_raw (const T &a, const T &b) noexcept
 Returns true if both values are equal disregarding epsilon but considering NaN, -Inf and +Inf. More...
 
constexpr float jau::float_value (const uint32_t a) noexcept
 Converting IEEE 754 (IEC 559) single floating-point bit layout to float, see bit_value() More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::is_zero (const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true if the given value is less than epsilon, w/ epsilon > 0. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::is_zero2f (const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true if all given values a and b are less than epsilon, w/ epsilon > 0. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::is_zero3f (const T &a, const T &b, const T &c, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true if all given values a, b and c are less than epsilon, w/ epsilon > 0. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::is_zero4f (const T &a, const T &b, const T &c, const T &d, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
 Returns true if all given values a, b, c and d are less than epsilon, w/ epsilon > 0. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr jau::is_zero_raw (const T &a) noexcept
 Returns true if the given value is zero, disregarding epsilon but considering NaN, -Inf and +Inf. More...
 
template<class T >
std::enable_if< std::is_floating_point_v< T >, T >::type jau::machineEpsilon () noexcept
 Calculates the smallest floating point value approximation the given type T can represent, the machine epsilon of T. More...
 
template<typename T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
std::string & jau::mat_to_string (std::string &sb, const std::string &rowPrefix, const std::string &f, const T a[], const jau::nsize_t rows, const jau::nsize_t columns, const bool rowMajorOrder) noexcept
 Appends a matrix of floating points to the given string sb More...
 
template<typename T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
constexpr T jau::rad_to_adeg (const T rad) noexcept
 Converts radians to arc-degree. More...
 
template<class T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
constexpr jau::sint_bytes< sizeof(T)>::type jau::round_to_int (const T v) noexcept
 Returns the rounded value cast to int. More...
 
template<typename T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true>
std::string & jau::row_to_string (std::string &sb, const std::string &f, const T a[], const jau::nsize_t rows, const jau::nsize_t columns, const bool rowMajorOrder, const jau::nsize_t row) noexcept
 Appends a row of floating points to the given string sb More...
 

Variables

constexpr uint64_t const jau::double_iec559_exp_mask = 0x7ff0000000000000_u64
 Exponent mask bits 52-62 of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint64_t const jau::double_iec559_mant_mask = 0x000fffffffffffff_u64
 Mantissa mask bits 0-51 of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint64_t const jau::double_iec559_nan_bitval = 0x7ff8000000000000_u64
 NaN bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint64_t const jau::double_iec559_negative_inf_bitval = 0xfff0000000000000_u64
 Negative infinity bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint64_t const jau::double_iec559_positive_inf_bitval = 0x7ff0000000000000_u64
 Positive infinity bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint64_t const jau::double_iec559_sign_bit = 1_u64 << 63
 Signed bit 63 of IEEE 754 (IEC 559) double double-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_exp_mask = 0x7f800000_u32
 Exponent mask bits 23-30 of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_mant_mask = 0x007fffff_u32
 Mantissa mask bits 0-22 of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_nan_bitval = 0x7fc00000_u32
 NaN bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_negative_inf_bitval = 0xff800000_u32
 Negative infinity bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_positive_inf_bitval = 0x7f800000_u32
 Positive infinity bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...
 
constexpr uint32_t const jau::float_iec559_sign_bit = 1_u32 << 31
 Signed bit 31 of IEEE 754 (IEC 559) single float-point bit layout, i.e. More...