tfel
Loading...
Searching...
No Matches
tfel::math::ieee754 Namespace Reference

Functions

constexpr int fpclassify (const float) noexcept
 a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org).
constexpr int fpclassify (const double) noexcept
 a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org)
constexpr bool isnan (const float) noexcept
 Determines if the given floating point number arg is a not-a-number (NaN) value.
constexpr bool isnan (const double) noexcept
 Determines if the given floating point number arg is a not-a-number (NaN) value.
TFEL_HOST_DEVICE bool isnan (const long double) noexcept
 Determines if the given floating point number arg is a not-a-number (NaN) value.
constexpr bool isfinite (const float) noexcept
 Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.
constexpr bool isfinite (const double) noexcept
 Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.
TFEL_HOST_DEVICE bool isfinite (const long double) noexcept
 Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.
TFEL_HOST_DEVICE int fpclassify (const long double) noexcept
 a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org)
template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr int fpclassify (const QuantityType &q) noexcept
template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr bool isnan (const QuantityType &q) noexcept
template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr bool isfinite (const QuantityType &q) noexcept

Detailed Description

The C99 standard defines the fpclassify, isnan, isfinite functions to query some information about double precision floatting-point numbers (double):

  • Following the IEEE754 standard, the fpclassify categorizes a floating point number into one of the following categories: zero, subnormal, normal, infinite, NaN (Not a Number). The return value returned for each category is respectively FP_ZERO, FP_SUBNORMAL, FP_NORMAL, FP_INFINITE and FP_NaN.
  • The isnan function returns a boolean stating if its argument has a not-a-number (NaN) value.
  • The isfinite function returns true if its argument falls into one of the following categories: zero, subnormal or normal.

The C++11 provides a set of overload for single precision (float) and extended precision (long double) floatting-point numbers.

Those functions are very handy to check the validity of a computation. However, those functions are not compatible with the use of the -ffast-math option of the GNU compiler which also implies the -ffinite-math-only option. This latter option allows optimizations for floating-point arithmetic that assume that arguments and results are finite numbers. As a consequence, when this option is enabled, the previous functions does not behave as expected. For example, isnan always returns false, whatever the value of its argument.

To overcome this issue, we have introduced in TFEL/Math the implementation of these functions provided by the musl library. Those implementations are compatible with the -ffast-math option of the GNU compiler. Those implementations are defined in the TFEL/Math/General/IEEE754.hxx header file in the tfel::math::ieee754 namespace.

Function Documentation

◆ fpclassify() [1/4]

int tfel::math::ieee754::fpclassify ( const double x)
constexprnoexcept

a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org)

Returns
the class of the floatting point value according to the IEEE754 standard. Possible return values are:
  • FP_NORMAL: standard floatting point value
  • FP_SUBNORMAL: subnormal floatting point value
  • FP_NAN: NaN value
  • FP_INFINITE: +Inf or -Inf value
Parameters
[in]xvalue to be tested

◆ fpclassify() [2/4]

int tfel::math::ieee754::fpclassify ( const float x)
constexprnoexcept

a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org).

Returns
the class of the floatting point value according to the IEEE754 standard. Possible return values are:
  • FP_NORMAL: standard floatting point value
  • FP_SUBNORMAL: subnormal floatting point value
  • FP_NAN: NaN value
  • FP_INFINITE: +Inf or -Inf value
Parameters
[in]xvalue to be tested

◆ fpclassify() [3/4]

TFEL_HOST_DEVICE int tfel::math::ieee754::fpclassify ( const long double )
noexcept

a portable implementation of the std::fpclassify function based on the MUSL library (https://www.musl-libc.org)

Returns
the class of the floatting point value according to the IEEE754 standard. Possible return values are:
  • FP_NORMAL: standard floatting point value
  • FP_SUBNORMAL: subnormal floatting point value
  • FP_NAN: NaN value
  • FP_INFINITE: +Inf or -Inf value
Parameters
[in]xvalue to be tested

◆ fpclassify() [4/4]

template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr int tfel::math::ieee754::fpclassify ( const QuantityType & q)
nodiscardconstexprnoexcept
Returns
the class of the floating point value according to the IEEE754 standard. Possible return values are:
  • FP_NORMAL: standard floating point value
  • FP_SUBNORMAL: subnormal floating point value
  • FP_NAN: NaN value
  • FP_INFINITE: +Inf or -Inf value
Parameters
[in]qvalue to be tested

◆ isfinite() [1/4]

bool tfel::math::ieee754::isfinite ( const double x)
constexprnoexcept

Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

Parameters
[in]xvalue to be tested
Returns
true if if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

◆ isfinite() [2/4]

bool tfel::math::ieee754::isfinite ( const float x)
constexprnoexcept

Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

Parameters
[in]xvalue to be tested
Returns
true if if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

◆ isfinite() [3/4]

TFEL_HOST_DEVICE bool tfel::math::ieee754::isfinite ( const long double x)
inlinenoexcept

Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

Parameters
[in]xvalue to be tested
Returns
true if if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.

◆ isfinite() [4/4]

template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr bool tfel::math::ieee754::isfinite ( const QuantityType & q)
nodiscardconstexprnoexcept
Returns
true if the given quantity is finite.
Parameters
[in]qvalue to be tested

◆ isnan() [1/4]

bool tfel::math::ieee754::isnan ( const double x)
constexprnoexcept

Determines if the given floating point number arg is a not-a-number (NaN) value.

Parameters
[in]xvalue to be tested
Returns
true if the given floating point number arg is a not-a-number (NaN) value.

◆ isnan() [2/4]

bool tfel::math::ieee754::isnan ( const float x)
constexprnoexcept

Determines if the given floating point number arg is a not-a-number (NaN) value.

Parameters
[in]xvalue to be tested
Returns
true if the given floating point number arg is a not-a-number (NaN) value.

◆ isnan() [3/4]

TFEL_HOST_DEVICE bool tfel::math::ieee754::isnan ( const long double x)
inlinenoexcept

Determines if the given floating point number arg is a not-a-number (NaN) value.

Parameters
[in]xvalue to be tested
Returns
true if the given floating point number arg is a not-a-number (NaN) value.

◆ isnan() [4/4]

template<ImmutableQuantityConcept QuantityType>
TFEL_HOST_DEVICE constexpr bool tfel::math::ieee754::isnan ( const QuantityType & q)
nodiscardconstexprnoexcept
Returns
true if the given quantity is a not-a-number (NaN) value.
Parameters
[in]qvalue to be tested