Utilities and Helpers
-
namespace aarith
Enums
-
enum IEEEClass
Enumeration of the different types of floating-points.
These are defined in Section 5.7.2. of the 2019 standard
Values:
-
enumerator signalingNaN
-
enumerator quietNaN
-
enumerator negativeInfinity
-
enumerator negativeNormal
-
enumerator negativeSubnormal
-
enumerator negativeZero
-
enumerator positiveZero
-
enumerator positiveSubnormal
-
enumerator positiveNormal
-
enumerator positiveInfinity
-
enumerator UNCLASSIFIED
-
enumerator signalingNaN
Functions
-
template<typename F>
bool constexpr isSignMinus(const F &f) Tests whether a floating-point number is negative.
isSignMinus(x) is true if and only if x has negative sign. isSignMinus applies to zeros and NaNs as well.
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is negative
-
template<typename F>
bool constexpr isNormal(const F &f) Tests whether a floating-point number is normal.
isNormal(f) is true if and only if f is normal (not zero, subnormal, infinite, or NaN)
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is normal
-
template<typename F>
bool constexpr isFinite(const F &f) Tests whether a floating-point number is finite.
isFinite(f) is true if and only if f is zero, subnormal or normal (not infinite or NaN).
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is finite
-
template<typename F>
bool constexpr isZero(const F &f) Tests whether a floating-point number is zero (ignoring the sign).
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is +/- zero
-
template<typename F>
bool constexpr isSubnormal(const F &f) Tests whether a floating-point number is zero (ignoring the sign).
Note
Zero is not considered subnormal!
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is +/- zero
-
template<typename F>
bool constexpr isInfinite(const F &f) Tests whether a floating-point number is infinite (ignoring the sign)
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is infinite
-
template<typename F>
bool constexpr isNaN(const F &f) Tests whether a floating-point number is NaN.
Note
This method does not distinguish between signalling and quiet NaNs
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is NaN
-
template<typename F>
bool constexpr isSignaling(const F &f) Tests whether a floating-point number is a signaling NaN.
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is a signaling NaN
-
template<typename F>
bool constexpr isQuiet(const F &f) Tests whether a floating-point number is a quiet NaN.
Note
This method is not required by the IEEE 754 standard
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True iff the number is a quiet NaN
-
template<typename F>
constexpr IEEEClass fp_class(const F &f) Determines the class (e.g. NaN, positive subnormal) of a floating-point number.
This method corresponds to the “class” method described in Section 5.7.2 of the 2019 standard. The function name had to be changed as C++ does not allow to name functions “class”.
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
The class of the floating-point number
-
template<typename F>
Radix constexpr radix([[maybe_unused]] const F &f) Returns the radix of the floating-point number.
Aarith only supports base two, hence Radix::Two is the only return value.
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
-
template<typename F>
bool constexpr isCanonical([[maybe_unused]] const F &f) Tests whether a floating-point number is canonical.
Aarith does not support non-canonical numbers hence this method always returns true.
- Template Parameters
F – The floating-point type
- Parameters
f – The floating-point number to test
- Returns
True
-
template<typename F, typename = std::enable_if_t<std::is_floating_point<F>::value>>
constexpr size_t get_mantissa_width()
-
template<>
constexpr size_t get_mantissa_width<float>()
-
template<>
constexpr size_t get_mantissa_width<double>()
-
template<typename F, typename = std::enable_if_t<std::is_floating_point<F>::value>>
constexpr size_t get_exponent_width()
-
template<>
constexpr size_t get_exponent_width<float>()
-
template<>
constexpr size_t get_exponent_width<double>()
-
template<typename F, typename = std::enable_if_t<std::is_floating_point<F>::value>>
inline auto disassemble_float(F num) -> float_disassembly
-
struct float_disassembly
-
enum IEEEClass
NaN Payloads
Header aarith/float/nan_payload.hpp
Giving access to the payloads encoded in NaN values is mandatory as per [IEEE754].
-
namespace aarith
Functions
-
template<size_t E, size_t M, typename WordType>
floating_point<E, M, WordType> constexpr getPayload(const floating_point<E, M, WordType> &x) Extracts the payload from an NaN.
- Template Parameters
E – Exponent width
M – Mantissa width
WordType – The data type the underlying data is stored in
- Parameters
x – Floating-point to extract the payload from
- Returns
The payload or -1, when x is not NaN
-
template<size_t E, size_t M, typename WordType>
floating_point<E, M, WordType> constexpr setPayload(const floating_point<E, M, WordType> &x) Creates quiet NaN with a specified payload.
For some reason, negative parameters result in +0 to be returned. Don’t ask me, ask the standard.
- Template Parameters
E – Exponent width
M – Mantissa width
WordType – The data type the underlying data is stored in
- Parameters
x – Floating-point number to take the payload to be stored from
- Returns
A quiet NaN with the specified payload, +0 in case of error
-
template<size_t E, size_t M, typename WordType>
floating_point<E, M, WordType> constexpr setPayloadSignaling(const floating_point<E, M, WordType> &x) Creates signaling NaN with a specified payload.
For some reason, negative parameters result in +0 to be returned. Don’t ask me, ask the standard.
- Template Parameters
E – Exponent width
M – Mantissa width
WordType – The data type the underlying data is stored in
- Parameters
x – Floating-point number to take the payload to be stored from
- Returns
A signaling NaN with the specified payload, +0 in case of error
-
template<size_t E, size_t M, typename WordType>