std::numeric_limits<T>::has_denorm
From cppreference.com
static const std::float_denorm_style has_denorm;
|
(until C++11) | |
static constexpr std::float_denorm_style has_denorm;
|
(since C++11) (deprecated in C++23) |
|
The value of std::numeric_limits<T>::has_denorm identifies the floating-point types that support subnormal values.
Standard specializations
T
|
value of std::numeric_limits<T>::has_denorm
|
/* non-specialized */
|
std::denorm_absent |
bool
|
std::denorm_absent |
char
|
std::denorm_absent |
signed char
|
std::denorm_absent |
unsigned char
|
std::denorm_absent |
wchar_t
|
std::denorm_absent |
char8_t (since C++20)
|
std::denorm_absent |
char16_t (since C++11)
|
std::denorm_absent |
char32_t (since C++11)
|
std::denorm_absent |
short
|
std::denorm_absent |
unsigned short
|
std::denorm_absent |
int
|
std::denorm_absent |
unsigned int
|
std::denorm_absent |
long
|
std::denorm_absent |
unsigned long
|
std::denorm_absent |
long long (since C++11)
|
std::denorm_absent |
unsigned long long (since C++11)
|
std::denorm_absent |
float
|
usually std::denorm_present |
double
|
usually std::denorm_present |
long double
|
usually std::denorm_present |
Example
Run this code
#include <iostream>
#include <limits>
#include <string_view>
template<typename... T>
constexpr bool denorm_absent =
((std::numeric_limits<T>::has_denorm == std::denorm_absent) and ...);
static_assert(denorm_absent<
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
>);
auto to_string(std::float_denorm_style e) -> std::string_view
{
switch (e)
{
case std::denorm_indeterminate: return "denorm_indeterminate";
case std::denorm_absent: return "denorm_absent";
case std::denorm_present: return "denorm_present";
}
return "?";
}
int main()
{
std::cout << to_string(std::numeric_limits<float>::has_denorm) << '\n';
}
Possible output:
denorm_present
See also
[static] |
returns the smallest positive subnormal value of the given floating-point type (public static member function) |
| indicates floating-point denormalization modes (enum) |