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

前端 未结 2 1952
别那么骄傲
别那么骄傲 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 15:55

    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 defines a couple of members which seem to imply that the representation is some in the form of significand radix exponent:

    • std::numeric_limits::radix: the radix of the exponent
    • std::numeric_limtis::digits: the number of radix digits

    I think these statements imply that you can represent integers in the range of 0 ... radix digits - 1 exactly.

提交回复
热议问题