Live data from Hacker News

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

lemire.me

151–158 of 158 posts

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

#151
post #149

Earlier quoted context omitted.

My argument was for the other direction, using [0,1) when you actually want [0,1]. I agree that if 1.0 would cause a problem in your code you should use a rng that avoids it. All of the floating point random number generators I'm familiar with deliver [0,1).

Interesting, I assumed java and javascripts behaviour were common. I dont recall seeing this notation before either [0,1) maybe i will now %)

I usually use C++ or Python, so I had to look up the others.

From Java: "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0."

From Javascript: "Return a random number between 0 (inclusive) and 1 (exclusive)"

So yes, all 4 are consistent in not including 1.0 in the range of random real numbers. I'd call that common.

For more on the notation see https://en.wikipedia.org/wiki/Interval_(mathematics)#Includi...

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

#152
post #151

Earlier quoted context omitted.

Interesting, I assumed java and javascripts behaviour were common. I dont recall seeing this notation before either [0,1) maybe i will now %)

I usually use C++ or Python, so I had to look up the others. From Java: "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0." From Javascript: "Return a random number between 0 (inclusive) and 1 (exclusive)" So yes, all 4 are consistent in not including 1.0 in the range of random real numbers. I'd call that common. For more on the notation see https://en.wikipedia.org/wiki/Int…

Apologies I wasn't following properly, and thanks for the interval math pointer.

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

#153
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.

Hmmm, I missed that wrinkle. My grasp of this slightly unusual topic is not 100% reliable, and so I'm now wondering whether the cardinality of the set you describe is different from the cardinality of the set of all possible floating point numbers.

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

#154
post #58

Earlier quoted context omitted.

John Gustafson’s new “sigmoid unum”/“posit” proposal is kind of interesting; see his recent talk: http://web.stanford.edu/class/ee380/Abstracts/170201.html https://news.ycombinator.com/item?id=13562164 It does a variable number of fraction bits, so that the values near 1 are even more densely represented than under the usual IEEE floats, while also providing greater dynamic range (but at reduced precision). I made a…

Out of curiosity, I started watching this talk, but right there in the introduction, the very first example is a dot product where supposedly IEEE 754 double precision gets the wrong answer; I stopped to check the result, and I got the correct answer with double precision (even without binary sum collapse). Then, he says the x87's results are nondeterministic due to being affected by cache, which is incorrect. Then,…

Doubles on my Intel give correct answer too, but change the exponent used everywhere to 8 and you'll see the problem. Gustafson may have used different implementation of IEEE 754 that gave him different result.

There are problems with repeatability of float operations such as loss of precision when moving value from registers to memory and data alignment issues, but it seems that these can be avoided with proper compiler options, at the expense of speed.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

https://software.intel.com/en-us/articles/run-to-run-reprodu...

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

#155
post #154
post #58

Earlier quoted context omitted.

Out of curiosity, I started watching this talk, but right there in the introduction, the very first example is a dot product where supposedly IEEE 754 double precision gets the wrong answer; I stopped to check the result, and I got the correct answer with double precision (even without binary sum collapse). Then, he says the x87's results are nondeterministic due to being affected by cache, which is incorrect. Then,…

Doubles on my Intel give correct answer too, but change the exponent used everywhere to 8 and you'll see the problem. Gustafson may have used different implementation of IEEE 754 that gave him different result. There are problems with repeatability of float operations such as loss of precision when moving value from registers to memory and data alignment issues, but it seems that these can be avoided with proper comp…

There is no "different implementation of IEEE 754" that could give a different result in double precision for that example.

There are reasonable criticisms of IEEE 754; that's not the issue.

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

#156
post #154

Earlier quoted context omitted.

Doubles on my Intel give correct answer too, but change the exponent used everywhere to 8 and you'll see the problem. Gustafson may have used different implementation of IEEE 754 that gave him different result. There are problems with repeatability of float operations such as loss of precision when moving value from registers to memory and data alignment issues, but it seems that these can be avoided with proper comp…

There is no "different implementation of IEEE 754" that could give a different result in double precision for that example. There are reasonable criticisms of IEEE 754; that's not the issue.

> There is no "different implementation of IEEE 754" that could give a different result in double precision for that example.

How do you know that?

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

#157
post #156

Earlier quoted context omitted.

There is no "different implementation of IEEE 754" that could give a different result in double precision for that example. There are reasonable criticisms of IEEE 754; that's not the issue.

> There is no "different implementation of IEEE 754" that could give a different result in double precision for that example. How do you know that?

IEEE 754 is a standard, and it requires a specific, bitwise-reproducible, answer for the computation in question. I'm the author of most of the floating-point tests in WebAssembly's conformance testsuite, which tests such things in practice across several hardware platforms.

One of the half-truths in the presentation (in the intro) is that IEEE 754 is a mixture of requirements and recommendations. IEEE 754 does have both requirements and recommendations, however what the presentation doesn't say is that, within a given format like double precision (aka binary64), the basic operations like add, subtract, multiply, divide, squareRoot, etc.) have exactly one possible result for any given input (except that NaNs may have some implementation-defined bits, though this is usually unimportant).

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

#158

Earlier quoted context omitted.

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.)

>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. pi

Oh.

pi - 3

Post reply on HN