Live data from Hacker News

How many floating-point numbers are in the interval [0,1]?

lemire.me

1–10 of 158 posts

Re: How many floating-point numbers are in the interval [0,1]?

#5

What about nan? The test '!(x 1)' will say yes, while 'x >= 0 && x Or -0 for that matter.

Common sense approach: like the name says, NaN is not a number. The question was about floating point numbers, not floating point values. So I suppose we shouldn't count NaN. Further, -0 (an arbitrarily small number less than 0) doesn't logically fall in the range [0, 1], so it is excluded.

Re: How many floating-point numbers are in the interval [0,1]?

#7
post #6

Article says 1,056,964,609 / 1,056,964,610 Quick Java program says 1,065,353,216 / 1,065,353,217 Which one is right? Or are Java floats just "different"? static { float a = 0; long count = 0; while (a

It might depend on the precise representation. This has become increasingly standardized lately which is why those numbers are really close and not wildly off.

Re: How many floating-point numbers are in the interval [0,1]?

#8
> Of all the float-pointing point numbers your computer can represent, a quarter of them lie in [0,1].

Many people think floating point numbers are magically precise. They're not. They're far more accurate at lower magnitudes and precision fades as you work with larger values.

Re: How many floating-point numbers are in the interval [0,1]?

#10
post #6

Article says 1,056,964,609 / 1,056,964,610 Quick Java program says 1,065,353,216 / 1,065,353,217 Which one is right? Or are Java floats just "different"? static { float a = 0; long count = 0; while (a

nextAfter is probably also including the denormals (an additional 2^23 values near 0).
Post reply on HN