std::numeric_limits<T>::is_iec559
From cppreference.com
static const bool is_iec559;
|
(until C++11) | |
static constexpr bool is_iec559;
|
(since C++11) | |
The value of std::numeric_limits<T>::is_iec559 is true for all floating-point types T which fulfill the requirements of IEC 559 (IEEE 754) standard. If std::numeric_limits<T>::is_iec559 is true, then std::numeric_limits<T>::has_infinity, std::numeric_limits<T>::has_quiet_NaN, and std::numeric_limits<T>::has_signaling_NaN are also true.
Standard specializations
T
|
value of std::numeric_limits<T>::is_iec559
|
/* non-specialized */
|
false
|
bool
|
false
|
char
|
false
|
signed char
|
false
|
unsigned char
|
false
|
wchar_t
|
false
|
char8_t (since C++20)
|
false
|
char16_t (since C++11)
|
false
|
char32_t (since C++11)
|
false
|
short
|
false
|
unsigned short
|
false
|
int
|
false
|
unsigned int
|
false
|
long
|
false
|
unsigned long
|
false
|
long long (since C++11)
|
false
|
unsigned long long (since C++11)
|
false
|
float
|
usually true
|
double
|
usually true
|
long double
|
usually true
|
Example
Run this code
#include <limits>
#include <print>
template <typename... Types>
constexpr bool iec559 = (std::numeric_limits<Types>::is_iec559 or ...);
static_assert(not iec559<
bool, char, signed char, unsigned char, wchar_t, char8_t, char16_t, char32_t, short,
unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long
>);
template <typename T>
constexpr bool validate = []
{
if constexpr (std::numeric_limits<T>::is_iec559)
return
std::numeric_limits<T>::has_infinity and
std::numeric_limits<T>::has_quiet_NaN and
std::numeric_limits<T>::has_signaling_NaN;
return true;
}();
static_assert(validate<float> and validate<double> and validate<long double>);
int main()
{
std::println("{}", std::numeric_limits<float>::is_iec559);
}
Possible output:
true
See also
[static] |
identifies floating-point types that can represent the special value “positive infinity” (public static member constant) |
[static] |
identifies floating-point types that can represent the special value “quiet not-a-number” (NaN) (public static member constant) |
[static] |
identifies floating-point types that can represent the special value “signaling not-a-number” (NaN) (public static member constant) |