Number of floats between two floats

后端 未结 4 1931
一整个雨季
一整个雨季 2021-02-20 03:41

Say I have two Python floats a and b, is there an easy way to find out how many representable real numbers are between the two in IEEE-754 representati

4条回答
  •  鱼传尺愫
    2021-02-20 04:03

    For positive numbers b > a > 0, the answer is approximately:

    (2**52) ** (log(b,2) - log(a,2))
    

    There are 52 bits of mantissa ( past the implied 1 ), multiplied by 2 raised to an exponent.

    So there are 2**52 numbers in range [1:2) as in the range [1024:2048)

提交回复
热议问题