C++'s std::numeric_limits<float>::digits10
, is described on cppref as such:
The value of
std::numeric_limits<T>::digits10
is the number of base-10 digits that can be represented by the type T without change, that is, any number with this many decimal digits can be converted to a value of type T and back to decimal form, without change due to rounding or overflow.
A similar description exists for the C cousin FLT_DIG.
The value given is:
float FLT_DIG /* 6 for IEEE float */
However, it is shown here on S.O. that all integers up to 16,777,216
(224) are exactly representable in a 32 bit IEEE float type. And if I can count, that number has 8 digits, so the value for digits10
should actually be 7, now shouldn't it?
Rather obviously, I misunderstand something about digits10
here, so what does this actually tell me?
Practical applicability:
I was asked if we could store all numbers from 0.00
- 86,400.00
exactly in an IEEE 32 bit float.
Now, I'm very confident that we could store all numbers from 0
- 8,640,000
in an IEEE 32 bit float, but does this hold for the same "integer" range shifted by 2 digits to the left?