Std :: numeric_limits <T> :: numeric values ​​for floating point types T in C ++, GCC compiler

I am using the gcc compiler (Linux, gcc --version is 4.8.2) for C ++ programming. I am interested template specification std::numeric_limits<T>

for floating point types T

( float

, double

, long double

). In particular, I'm interested in a static member value static constexpr int digits

for the std::numeric_limits<T>

for the floating-point types T

.

As far as I know, the current C ++ standard says that a value digits

is the number of digits in a string in the number of a mantissa. I have printed the value std::numeric_limits<T>::digits

for different floating point types on my machine (floating point types implement IEEE754 according to the field std::numeric_limits<T>::is_iec559

) and I am a little surprised with the result: Ie for T=float

he says 24

.

I understand that the Single type (i.e. float

) has - according to IEEE754 - a mantissa (floating point value) of 23 bits (while there is 1 sign bit and an exponent of 8 bits, so there are only 32 bits). So why is it digits

set to 24

? The value digits

for double

is 53

instead of 52 (the number of bits in the mantissa for Double according to IEEE754).

Possibly some subtle (or not so subtle?) Floating point issue, but I would like to know.

+3


source to share





All Articles