The number of bits for the mantissa, exponent and sign of a long double
value can be detected in the following way (supposing iec559):
template <typename T>
constexpr uint32_t bitsInExponent()
{
static_assert(std::numeric_limits<T>::is_iec559);
return std::ceil(std::log2(std::numeric_limits<T>::max_exponent-std::numeric_limits<T>::min_exponent+1));
}
// outputs 15 for long double on my machine/compiler
template <typename T>
constexpr uint32_t bitsInMantissa()
{
static_assert(std::numeric_limits<T>::is_iec559);
static_assert(std::numeric_limits<T>::radix == 2);
return std::numeric_limits<T>::digits-1;
}
// outputs 63 for long double on my machine/compiler
template <typename T>
constexpr uint32_t bitsInSign()
{
return 1;
}
Consequently, the total number of bits for the long double
is (on my machine and compiler) 79 (63+15+1), probably a IEEE-754 binary64 extended format.
However, the memory footprint of the long double
(sizeof(long double)
) is 16, thus 128 bits.
The padding of the float value (those 128-79, 49bits) seems to be at the higher bits on my machine with my compiler, and mostly filled with garbage.
My question is: Are those 1-63 bits always at the higher bits of the 128 bits?
In case the padding of the extended IEEE-754 binary-64 format is not guaranteed to be at the highest bits, how to detect where is the padding?
Try it: https://onlinegdb.com/doL6E7WYL