Does the C++03 standard guarantee that sufficiently small non-zero integers are represented exactly in double
? If not, what about C++11? Note, I am not assuming
Well, 3.9.1 [basic.fundamental] paragraph 8 states
... The value representation of floating-point types is implementation-defined. ...
At least, the implementation has to define what representation it uses.
On the other hand, std::numeric_limits<F>
defines a couple of members which seem to imply that the representation is some in the form of significand radix exponent:
std::numeric_limits<F>::radix
: the radix of the exponentstd::numeric_limtis<F>::digits
: the number of radix
digitsI think these statements imply that you can represent integers in the range of 0
... radix digits - 1 exactly.
From the C standard, "Characteristics of floating types <float.h>
", which is normative for C++, I would assume that you can combine FLT_RADIX
and FLT_MANT_DIG
into useful information: The number of digits in the mantissa and the base in which they are expressed.
For example, for a single-precision IEEE754 float, this would be respectively 2 and 24, so you should be able to store integers of absolute value up to 224.