News for hackers. Stuff that matters.
Re:Lies My Calculator and Computer Told Me [pdf] by quickthrower2 on Tuesday September 19, 2023 @09:16AM (#37569526)
Floating point values are not numbers. They are ranges. They are approximately a field like entity-ish.
Re:Lies My Calculator and Computer Told Me [pdf] by repiret on Tuesday September 19, 2023 @09:37AM (#37569768)
In what way do they behave like ranges?

I generally prefer to think of them as they are: able to represent a subset of the rationals, plus a couple other weird values, but not a field, and importantly, not obeying any of the usual algebraic laws with arithmetic.

Re:Lies My Calculator and Computer Told Me [pdf] by lmm on Tuesday September 19, 2023 @06:45PM (#37578081)
Yep. Floating point addition is not even associative, so they're not only not a field, but not a ring, not a group, nor even a monoid.
Re:Lies My Calculator and Computer Told Me [pdf] by voluntaryeuth on Tuesday September 19, 2023 @09:38AM (#37569784)
Can you point me to a reference?

Every floating point article (including IEEE 754) I've seen treats normal floating point numbers as dyadic rationals.

Re:Lies My Calculator and Computer Told Me [pdf] by tgv on Tuesday September 19, 2023 @10:00AM (#37570047)
I don't think you can see them as a range. Sure, you can think of the float representation of 0.1 and 0.2 as a small range around those values, but what does that make 0.1 + 0.2, or 0.1 * 0.2, or 0.1 ** 0.2? Now the resulting float no longer represents the range of potential conversion error.

And at the same time, integer values (up until some decently high numbers) are represented correctly, so they would need a different range.

Re:Lies My Calculator and Computer Told Me [pdf] by Majromax on Tuesday September 19, 2023 @10:12AM (#37570210)
Floating point values are binary scientific notation with a fixed precision. All of the unintuitive behaviour of floats is repeated if you imagine conducting decimal calculations yourself in said scientific notation, with intermediate rounding at every step.

Floats are only ranges in that each real number (within the overall range limit) has a unique floating point representation to which it is closest, up to rounding at the precise interval boundary.

Floats can be extended to interval arithmetic, but doing so requires the extra work of keeping track of interval limits. When calculations lose precision (through cancellation of digits in the floating point representation), the interval of uncertainty is larger than the floating point precision.

Re:Lies My Calculator and Computer Told Me [pdf] by orlp on Tuesday September 19, 2023 @10:36AM (#37570591)
IEEE 754 floating point are numbers, they are not ranges. Every operation rounds to a representable number in the set.
Re:Lies My Calculator and Computer Told Me [pdf] by BeetleB on Tuesday September 19, 2023 @10:58AM (#37570854)
Everyone is correcting you, but no one is pointing out the real culprit. Floating point operations are not the same as math operations (i.e. +, -, *, / behave differently).
Re:Lies My Calculator and Computer Told Me [pdf] by ska on Tuesday September 19, 2023 @12:33PM (#37572425)
I think what you mean here is that floating point numbers an the usual operators (+,*) and inverses (-,/) do not form a field, but people often behave as if they do.

This isn't a "culprit" so much as a fact along with common confusion.

Re:Lies My Calculator and Computer Told Me [pdf] by gilcot on Tuesday September 19, 2023 @01:11PM (#37573014)
IEEE 754 is well defined so that $a+b=b+a$ But it can't give you warranty that $(a+b)+c=a+(b+c)$ (well known error propagation issue)
Re:Lies My Calculator and Computer Told Me [pdf] by BeetleB on Tuesday September 19, 2023 @05:21PM (#37576915)
IEEE guarantees commutativity, but does not guarantee the correctness of a+b.

My point is that floating point numbers are real numbers, but the usual operations on them will not give you the same results as the operations on real numbers.

Re:Lies My Calculator and Computer Told Me [pdf] by nayuki on Tuesday September 19, 2023 @08:01PM (#37578771)
IEEE does guarantee the correctness of a+b in the sense that it will return the floating-point number that is closest to the real number that would've been computed with infinite precision.
Re:Lies My Calculator and Computer Told Me [pdf] by BeetleB on Wednesday September 20, 2023 @12:33PM (#37586312)
> IEEE does guarantee the correctness of a+b in the sense that it will return the floating-point number that is closest to the real number that would've been computed with infinite precision.

Until you deal with overflow.

And to be frank, this is just redefining "correctness". If you want to view FPs as real numbers (which they are), there's nothing wrong with pointing out that real number operations will give you incorrect results (even ignoring overflow).

> There's no randomness or fuzziness in floating-point rounding.

I did not imply there was.

Re:Lies My Calculator and Computer Told Me [pdf] by gilcot on Tuesday September 19, 2023 @09:34PM (#37579417)
FP are part of R, like Q or D sets. (I think it should be considered/seen as a subset of decimal numbers set.)
Re:Lies My Calculator and Computer Told Me [pdf] by BeetleB on Wednesday September 20, 2023 @12:34PM (#37586314)
Nothing I said implied they weren't.