Re:How many floating-point numbers are in the interval [0,1]?
by AimHere on Thursday March 02, 2017 @05:42AM
(#13773102)
I'll not endorse your actual line of argument, but without knowing much about the internals of a 32-bit float, I can confirm that your final answer is correct.
Source: brute force counting in a small C program.
Naturally, this might not scale to 64-bits, unless you have lots of time and computing power to spare.
Re:How many floating-point numbers are in the interval [0,1]?
by Lanzaa on Thursday March 02, 2017 @01:28PM
(#13776742)
This type of off-by-one error is so common it has its own name: fencepost error[1].
One little note, is that I would disagree with your correction.
> This should be corrected to:
> > The number of values between the two is 0x3f800000 - 0x00000000 == 0x3f800001
I think the value originally computed was correct. It would make more sense to correct the wording rather than just the computed value.
i.e.
> The number of values in the range [0x00000000, 0x3f800000] is 0x3f800000 - 0x00000000 + 1 == 0x3f800001
[1]: https://en.wikipedia.org/wiki/Off-by-one_error#Fencepost_err...
Re:How many floating-point numbers are in the interval [0,1]?
by lightedman on Thursday March 02, 2017 @04:18AM
(#13772765)
I was under the impression (after several thousand attempts) that the correct answer is infinity, limited only by your addressable memory and bitspace.
Re:How many floating-point numbers are in the interval [0,1]?
by afandian on Thursday March 02, 2017 @07:07AM
(#13773471)
I think people are assuming IEEE 754 floating point (as per the article). Your memory is finite, 32 bits. https://en.wikipedia.org/wiki/Floating_point
> The number of values between the two is 0x3f800000 - 0x00000000 == 0x3f800000
This should be corrected to:
> The number of values between the two is 0x3f800000 - 0x00000000 == 0x3f800001
In general, the number of numbers in the closed integral interval [a, b] is not b-a, but 1+b-a. For example, the closed interval [0,10] contains 11 integers, not 10.
(The above assumes that the original question assumes the floating point number -0 to be outside of [0,1]. Otherwise, you'll have to add 1 more.)