Is `double` guaranteed by C++03 to represent small integers exactly?

前端 未结 2 1956
别那么骄傲
别那么骄傲 2020-12-20 15:26

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

2条回答
  •  情话喂你
    2020-12-20 16:02

    From the C standard, "Characteristics of floating types ", 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.

提交回复
热议问题