Is there a standard conform and portable way to check at compile time, if all values of one floating point type can be represented within another floating point type? Please also consider upcoming types like std::bfloat16_t.
I found this:
- A float is a guaranteed subset of double
- A double is a guaranteed subset of long double
- And of course a float is a guaranteed subset of a long double
I could specialize a predicate at least for these combinations.
From cppreference:
long double — extended precision floating-point type. Matches IEEE-754 binary128 format if supported, otherwise matches IEEE-754 binary64-extended format if supported, otherwise matches some non-IEEE-754 extended floating-point format as long as its precision is better than binary64 and range is at least as good as binary64, otherwise matches IEEE-754 binary64 format.
If I read this correctly, long double can at least represent all values of IEEE-754 binary64. This information could be used to compare the fixed types with long double. Of course only if cppreference is right.