top | item 41112688

(no title)

a1369209993 | 1 year ago

> The number of floats between 0 and 1 is the same as the number of floats between 1 and 3

No, the number of floats between 0 and 1 is (approximately) the same as the number of floats between 1 and positive infinity. And this is the correct way for it work: 1/x has roughly the same range and precision as x, so you don't need (as many) stupid obfuscatory algebraic transforms in your formulas to keep your intermediate values from over- or under-flowing.

discuss

order

anchpop|1 year ago

I think you're right. I produced a small rust program to test it by iterating over all 32-bit floats: https://gist.github.com/anchpop/30f119efd8d4c29a6a99202d57a5...

Output:

    Count between 0 and 1:    1065353215
    Count between 1 and +inf: 1073741824
    Ratio: 1.0
But a more theoretical approach will probably be needed to see if the same ratio exists for 64 bit floats.

llm_trw|1 year ago

Floating points numbers have a fix precision mantissa, and a fixed precision exponent.

So you have xxxxx E xxx as an example of a 5 bit mantissa and 3 bit exponent.

You have 2^5 floating point numbers for each possible exponent.

So no, you're wrong. For exponent 0 you have 2^5, and for exponent 1, 10 and 11 you then have the same. The exponent 0b (0d) then contain the same number of possible floating mantissas as does 1b (1d), 10b (2d) and 11b(3d). Which means that there are as many mantissas between [0,1) as there are between [1,3)

greg7mdp|1 year ago

> for exponent 1, 10 and 11 you then have the same

Right. But the exponent is signed as well, so you have the same number of exponent values mapping to values between -1 and 1 (roughly exponent values from -127 to -1) as to all other values (between -inf and -1 and between 1 and inf), exponent values from 1 to 126.

nh23423fefe|1 year ago

why do you think the range [0,1) is represented by one exponent?