Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
Float types and arithmetic, see also and meta-group Math Support. More...
Namespaces | |
namespace | jau::float_literals |
Typedefs | |
typedef jau::uint_bytes< sizeof(double)>::type | jau::double_uint_t |
typedef float | jau::float32_t |
typedef double | jau::float64_t |
typedef jau::uint_bytes< sizeof(float)>::type | jau::float_uint_t |
typedef float | jau::si_lengthf32_t |
Length in fractions of meter using float. More... | |
typedef float | jau::si_massf32_t |
Mass in fractions of kilograms using float. More... | |
typedef float | jau::si_speedf32_t |
Speed in fractions of meter/seconds using float. More... | |
typedef float | jau::si_timef32_t |
Time in fractions of seconds using float. More... | |
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... | |
Float types and arithmetic, see also and meta-group Math Support.
typedef jau::uint_bytes<sizeof(float)>::type jau::float_uint_t |
Definition at line 53 of file float_math.hpp.
typedef jau::uint_bytes<sizeof(double)>::type jau::double_uint_t |
Definition at line 54 of file float_math.hpp.
typedef float jau::si_timef32_t |
Time in fractions of seconds using float.
Definition at line 36 of file float_si_types.hpp.
typedef float jau::si_lengthf32_t |
Length in fractions of meter using float.
Definition at line 38 of file float_si_types.hpp.
typedef float jau::si_massf32_t |
Mass in fractions of kilograms using float.
Definition at line 40 of file float_si_types.hpp.
typedef float jau::si_speedf32_t |
Speed in fractions of meter/seconds using float.
Definition at line 42 of file float_si_types.hpp.
typedef float jau::float32_t |
Definition at line 46 of file float_types.hpp.
typedef double jau::float64_t |
Definition at line 47 of file float_types.hpp.
|
noexcept |
Returns the unsigned integer representation according to IEEE 754 (IEC 559) floating-point bit layout.
Meaningful semantics are only given if true == std::numeric_limits<T>::is_iec559
.
This raw method does not collapse all NaN values.
The result is a functional unsigned integer that, i.e. reversible to double via float_value() or double via double_value() depending on type T
,
See specific semantics of IEEE 754 (IEC 559) single floating-point bit layout:
See specific semantics of IEEE 754 (IEC 559) double doubleing-point bit layout:
T | floating point type, e.g. float or double |
matching | floating point unsigned integer type, e.g. float_uint_t or double_uint_t |
a | float value |
Definition at line 129 of file float_math.hpp.
|
constexprnoexcept |
Returns the unsigned integer representation according to IEEE 754 (IEC 559) single floating-point bit layout.
See bit_value() for details.
This raw method does not collapse all NaN values to float_iec559_nan_bitval.
Definition at line 144 of file float_math.hpp.
|
constexprnoexcept |
Returns the unsigned integer representation according to IEEE 754 (IEC 559) single floating-point bit layout.
Meaningful semantics are only given if true == std::numeric_limits<float>::is_iec559
.
All NaN values which are represented by float_iec559_nan_bitval.
The result is a functional unsigned integer that, i.e. reversible to double via float_value().
See specific semantics of IEEE 754 (IEC 559) single floating-point bit layout:
The result is a functional unsigned integer that, i.e. reversible to float via float_value(), except all NaN values which are represented by float_iec559_nan_bitval.
a | single float value |
Definition at line 174 of file float_math.hpp.
|
constexprnoexcept |
Converting IEEE 754 (IEC 559) single floating-point bit layout to float, see bit_value()
Definition at line 182 of file float_math.hpp.
|
constexprnoexcept |
Returns the unsigned integer representation according to IEEE 754 (IEC 559) double floating-point bit layout.
See bit_value() for details.
This raw method does not collapse all NaN values to double_iec559_nan_bitval.
Definition at line 194 of file float_math.hpp.
|
constexprnoexcept |
Returns the unsigned integer representation according to IEEE 754 (IEC 559) double floating-point bit layout.
Meaningful semantics are only given if true == std::numeric_limits<double>::is_iec559
.
All NaN values which are represented by double_iec559_nan_bitval.
The result is a functional unsigned integer that, i.e. reversible to double via double_value().
See specific semantics of IEEE 754 (IEC 559) double floating-point bit layout:
a | double float value |
Definition at line 221 of file float_math.hpp.
|
constexprnoexcept |
Converting IEEE 754 (IEC 559) double floating-point bit layout to double, see bit_value()
Definition at line 228 of file float_math.hpp.
|
noexcept |
Calculates the smallest floating point value approximation the given type T can represent, the machine epsilon of T.
T | a non integer float type |
Definition at line 241 of file float_math.hpp.
|
constexprnoexcept |
Returns true if the given value is less than epsilon, w/ epsilon > 0.
Definition at line 255 of file float_math.hpp.
|
constexprnoexcept |
Returns true if all given values a and b are less than epsilon, w/ epsilon > 0.
Definition at line 262 of file float_math.hpp.
|
constexprnoexcept |
Returns true if all given values a, b and c are less than epsilon, w/ epsilon > 0.
Definition at line 269 of file float_math.hpp.
|
constexprnoexcept |
Returns true if all given values a, b, c and d are less than epsilon, w/ epsilon > 0.
Definition at line 276 of file float_math.hpp.
|
constexprnoexcept |
Returns true if the given value is zero, disregarding epsilon
but considering NaN
, -Inf
and +Inf
.
Definition at line 286 of file float_math.hpp.
|
constexprnoexcept |
Returns -1
, 0
or 1
if a
is less, equal or greater than b
, disregarding epsilon but considering NaN
, -Inf
and +Inf
.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
Definition at line 307 of file float_math.hpp.
|
constexprnoexcept |
Returns -1
, 0
or 1
if a
is less, equal or greater than b
, considering epsilon and NaN
, -Inf
and +Inf
.
epsilon
must be > 0.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
epsilon | defaults to std::numeric_limits<T>::epsilon(), must be > 0 |
Definition at line 348 of file float_math.hpp.
|
constexprnoexcept |
Returns true if both values are equal disregarding epsilon but considering NaN
, -Inf
and +Inf
.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
Definition at line 371 of file float_math.hpp.
|
constexprnoexcept |
Returns true if both values are equal, i.e.
their absolute delta < epsilon
, considering epsilon and NaN
, -Inf
and +Inf
.
epsilon
must be > 0.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
epsilon | defaults to std::numeric_limits<T>::epsilon(), must be > 0 |
Definition at line 394 of file float_math.hpp.
|
constexprnoexcept |
Returns true if both values are equal, i.e.
their absolute delta < epsilon
, considering epsilon but disregarding NaN
, -Inf
and +Inf
.
T | a non integer float type |
a | value to compare |
b | value to compare |
Definition at line 413 of file float_math.hpp.
|
constexprnoexcept |
Returns true, if both floating point values are equal in the sense that their potential difference is less or equal epsilon * ulp
.
epsilon
must be > 0.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
ulp | desired precision in ULPs (units in the last place) |
epsilon | the machine epsilon of type T, defaults to std::numeric_limits<T>::epsilon() |
Definition at line 436 of file float_math.hpp.
|
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.
epsilon
must be > 0.
Implementation considers following corner cases:
T | a non integer float type |
a | value to compare |
b | value to compare |
ulp | desired precision in ULPs (units in the last place), defaults to 1 |
epsilon | the machine epsilon of type T, defaults to std::numeric_limits<T>::epsilon() |
Definition at line 460 of file float_math.hpp.
|
constexprnoexcept |
Returns the rounded value cast to int.
Definition at line 475 of file float_math.hpp.
|
constexprnoexcept |
Converts arc-degree to radians.
Definition at line 482 of file float_math.hpp.
|
constexprnoexcept |
Converts radians to arc-degree.
Definition at line 489 of file float_math.hpp.
|
noexcept |
Appends a row of floating points to the given string sb
sb | string buffer to appends to |
f | format string for each float element, e.g. "%10.5f" |
a | the float data of size rows x columns |
rows | float data a size row factor |
columns | float data a size column factor |
rowMajorOrder | if true floats are laid out in row-major-order, otherwise column-major-order (OpenGL) |
row | selected row of float data a |
sb
for chaining Definition at line 506 of file float_math.hpp.
|
noexcept |
Appends a matrix of floating points to the given string sb
sb | string buffer to appends to |
rowPrefix | prefix for each row |
f | format string for each float element, e.g. "%10.5f" |
a | the float data of size rows x columns |
rows | float data a size row factor |
columns | float data a size column factor |
rowMajorOrder | if true floats are laid out in row-major-order, otherwise column-major-order (OpenGL) |
sb
for chaining Definition at line 537 of file float_math.hpp.
|
constexpr |
Signed bit 31 of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0x80000000
.
Definition at line 57 of file float_math.hpp.
|
constexpr |
Exponent mask bits 23-30 of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0x7f800000
.
Definition at line 60 of file float_math.hpp.
|
constexpr |
Mantissa mask bits 0-22 of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0x007fffff
.
Definition at line 63 of file float_math.hpp.
|
constexpr |
Positive infinity bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0x7f800000
.
Definition at line 66 of file float_math.hpp.
|
constexpr |
Negative infinity bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0xff800000
.
Definition at line 69 of file float_math.hpp.
|
constexpr |
NaN bit-value of IEEE 754 (IEC 559) single float-point bit layout, i.e.
0x7fc00000
.
Definition at line 72 of file float_math.hpp.
|
constexpr |
Signed bit 63 of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0x8000000000000000
.
Definition at line 75 of file float_math.hpp.
|
constexpr |
Exponent mask bits 52-62 of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0x7ff0000000000000
.
Definition at line 78 of file float_math.hpp.
|
constexpr |
Mantissa mask bits 0-51 of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0x000fffffffffffff
.
Definition at line 81 of file float_math.hpp.
|
constexpr |
Positive infinity bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0x7ff0000000000000
.
Definition at line 84 of file float_math.hpp.
|
constexpr |
Negative infinity bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0xfff0000000000000
.
Definition at line 87 of file float_math.hpp.
|
constexpr |
NaN bit-value of IEEE 754 (IEC 559) double double-point bit layout, i.e.
0x7ff8000000000000
.
Definition at line 90 of file float_math.hpp.