Live data from Hacker News

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

lemire.me

21–30 of 158 posts

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

#21

(I invoke my pedant-pass.) As formulated in the title, "How many floating-point numbers are in the interval [0,1]?" you could argue that this is the cardinality of the Real Numbers. What the article says it is really talking about are single-precision IEEE 754 floating-point numbers. However, I could define any number of my own floating-point representations at various sizes. The cardinality of all possible floating…

What makes you think any arbitrary real number qualifies as a “floating point number”? I have never seen the term used in anything like that context. To me, the term “floating point number” is about number representation, not number identity. It is an inherently finite quantity in every instance I’ve ever seen. Examples of floating point numbers: The sexagesimal cuneiform 42 25 35 written on the Babylonian tablet YBC…

The GP is claiming that all possible floating point systems, taken together, would contain the same number of values as there are points on the real line.

Consider a floating point system based on https://en.wikipedia.org/wiki/Golden_ratio_base

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

#22

(I invoke my pedant-pass.) As formulated in the title, "How many floating-point numbers are in the interval [0,1]?" you could argue that this is the cardinality of the Real Numbers. What the article says it is really talking about are single-precision IEEE 754 floating-point numbers. However, I could define any number of my own floating-point representations at various sizes. The cardinality of all possible floating…

What makes you think any arbitrary real number qualifies as a “floating point number”? I have never seen the term used in anything like that context. To me, the term “floating point number” is about number representation, not number identity. It is an inherently finite quantity in every instance I’ve ever seen. Examples of floating point numbers: The sexagesimal cuneiform 42 25 35 written on the Babylonian tablet YBC…

You can make an exception for a particular bit pattern for an irrational, like Pi, just like you can use a particular bit pattern to represent -0 and NaN. Since the title doesn't specify a floating point representation, I thereby invoke all possible floating point representations. I construct a set of such representations with the cardinality of Reals like so: For any given real number X, just formulate a representation like single-precision IEEE 754 floating-point but which substitutes X for NaN.

The article doesn't fall into this trap, but the title does.

Now, if you think your objection sinks my definition of "floating point number," note that it also sinks IEEE 754 floating-point.

EDIT: So you formulate a particular definition of "floating point number" for which you are right. To which I say: So What?

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

#23
post #21

Earlier quoted context omitted.

What makes you think any arbitrary real number qualifies as a “floating point number”? I have never seen the term used in anything like that context. To me, the term “floating point number” is about number representation, not number identity. It is an inherently finite quantity in every instance I’ve ever seen. Examples of floating point numbers: The sexagesimal cuneiform 42 25 35 written on the Babylonian tablet YBC…

The GP is claiming that all possible floating point systems, taken together, would contain the same number of values as there are points on the real line. Consider a floating point system based on https://en.wikipedia.org/wiki/Golden_ratio_base

Thanks! To be just a bit more precise, I am claiming that all possible floating point systems, taken together, would contain the same number of values in [0,1] as there are points on the real line.

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

#24

(I invoke my pedant-pass.) As formulated in the title, "How many floating-point numbers are in the interval [0,1]?" you could argue that this is the cardinality of the Real Numbers. What the article says it is really talking about are single-precision IEEE 754 floating-point numbers. However, I could define any number of my own floating-point representations at various sizes. The cardinality of all possible floating…

This is not true, and I can think of at least two arguments.

First, the space of all computable reals is countable[1] (i.e. numbers which can be approximated by a sequence of rational numbers produced by a computable function). Note that this subsumes the irrational numbers as well.

Second, all floating point representations would individually have at most the cardinality of the natural numbers, even if the representation was arbitrarily sized (if they were finitely sized, they would of course each have finite cardinality). So you would need the space of possible representations to be uncountable. You would have to come up with a mighty strange notion of "floating point representation" that allowed you to have more distinct representations than computable functions, which again have the cardinality of the natural numbers. Even ignoring the fact that there will be overlap between the representations, we have an upper bound for the total cardinality as that of the set product of the natural numbers with itself, which is again the cardinality of the natural numbers.

[1]: https://en.wikipedia.org/wiki/Computable_number

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

#25

(I invoke my pedant-pass.) As formulated in the title, "How many floating-point numbers are in the interval [0,1]?" you could argue that this is the cardinality of the Real Numbers. What the article says it is really talking about are single-precision IEEE 754 floating-point numbers. However, I could define any number of my own floating-point representations at various sizes. The cardinality of all possible floating…

This is not true, and I can think of at least two arguments. First, the space of all computable reals is countable[1] (i.e. numbers which can be approximated by a sequence of rational numbers produced by a computable function). Note that this subsumes the irrational numbers as well. Second, all floating point representations would individually have at most the cardinality of the natural numbers, even if the represent…

Second, all floating point representations would individually have at most the cardinality of the natural numbers

All of that is irrelevant. I'm using the cardinality of all possible floating point representations. Give me a real in [0,1] that you say doesn't have a representation, and I will give you a floating point representation that will include it. (Using an operation that's just cut and paste on the IEEE one.)

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

#26

Earlier quoted context omitted.

This is not true, and I can think of at least two arguments. First, the space of all computable reals is countable[1] (i.e. numbers which can be approximated by a sequence of rational numbers produced by a computable function). Note that this subsumes the irrational numbers as well. Second, all floating point representations would individually have at most the cardinality of the natural numbers, even if the represent…

Second, all floating point representations would individually have at most the cardinality of the natural numbers All of that is irrelevant. I'm using the cardinality of all possible floating point representations. Give me a real in [0,1] that you say doesn't have a representation, and I will give you a floating point representation that will include it. (Using an operation that's just cut and paste on the IEEE one.)

Chaitin's constant for Turing Machines. Also note that I mentioned the cardinality of all representations in the next sentence.

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

#27
The correct answer is 1,065,353,216.

This is easy to work out yourself if you remember one basic, handy property of floats: adjacent floats are adjacent in bit representation, except -0.0f and 0.0f.

For example, 0x00000000 is +0.0f. 0x00000001 is the smallest non-zero positive float. 0x00000002 is the second smallest.

The only exception to this is -0.0f and +0.0f, which are 0x80000000 and 0x00000000. The rule works with denormal floats, normal floats, and even right on the line between the two. If you want the next positive float, you always just add 0x00000001.

Now, +1.0f happens to be 0x3f800000. Recall +0.0f is 0x00000000. The number of values between the two is 0x3f800000 - 0x00000000 == 0x3f800000. Write that in decimal and you get 1065353216.

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

#28
post #21

Earlier quoted context omitted.

The GP is claiming that all possible floating point systems, taken together, would contain the same number of values as there are points on the real line. Consider a floating point system based on https://en.wikipedia.org/wiki/Golden_ratio_base

Thanks! To be just a bit more precise, I am claiming that all possible floating point systems, taken together, would contain the same number of values in [0,1] as there are points on the real line.

[deleted]

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

#29
post #4

for many applications, consider randomizing in [1,2) and then subtracting one. Although many of the fp values in [0,1) will be inaccessible, you are guaranteed uniformity, and also the lattice that you're drawing from will be fixed.

How do randomize in [1,2)? You might as well just generate numbers from [0, 2^53) or [0, 2^24) and divide.

If you didn't do that on the way to generating in [1,2), you're going to have fine-grained non-uniformity anyway.

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

#30

Earlier quoted context omitted.

What makes you think any arbitrary real number qualifies as a “floating point number”? I have never seen the term used in anything like that context. To me, the term “floating point number” is about number representation, not number identity. It is an inherently finite quantity in every instance I’ve ever seen. Examples of floating point numbers: The sexagesimal cuneiform 42 25 35 written on the Babylonian tablet YBC…

You can make an exception for a particular bit pattern for an irrational, like Pi, just like you can use a particular bit pattern to represent -0 and NaN. Since the title doesn't specify a floating point representation, I thereby invoke all possible floating point representations. I construct a set of such representations with the cardinality of Reals like so: For any given real number X, just formulate a representat…

[deleted]
Post reply on HN