Representing integers in doubles

前端 未结 5 1009
难免孤独
难免孤独 2020-11-29 08:18

Can a double (of a given number of bytes, with a reasonable mantissa/exponent balance) always fully precisely hold the range of an unsigned integer of half that number of by

5条回答
  •  误落风尘
    2020-11-29 08:59

    Exactly what the range is that you can represent exactly depends on a lot of factors in your implementation, but you can lower-bound it by saying that, if the exponent field is set to 0, you can exactly represent integers up to the width of your mantissa field (assuming a sign bit). For IEEE 754 double-precision, this means you can represent 52-bit numbers exactly. In general, your mantissa will be over half the width of the overall structure.

提交回复
热议问题