News for hackers. Stuff that matters.
Re:GCC optimized code gives strange floating point results by mauvehaus on Sunday February 26, 2017 @06:30PM (#13740664)
> always compare it to be less than a small sigma.

Unfortunately, this approach can result in problems with the usual expectation that equality is transitive. Consider 0 < x < y < sigma. 0 == x, 0 == y, but x != y. This problem applies generally any time you're doing equality comparisons with sigma.

Re:GCC optimized code gives strange floating point results by SolarNet on Monday February 27, 2017 @05:26AM (#13743219)
You aren't following the instructions. You have to rewrite all comparisons to use a small sigma.

`0.f == x` becomes `SIGMA > x`

`0.f == y` becomes `SIGMA > y`

`x == y` becomes `SIGMA > abs(x - y)`

All the expression work if written correctly.

Re:GCC optimized code gives strange floating point results by mauvehaus on Monday February 27, 2017 @06:50AM (#13743553)
I probably should have given a better example instead of the hasty one. -sigma < x < 0 < y < sigma, abs(x - y) > sigma. I hope we can agree that this causes problems with transitivity :-)

There are also problems with granularity. Suppose x and y are both much, much larger than sigma, and the smallest representable difference between x and y is e.g. 1.0. Now there's no possible way that abs(x - y) < sigma.

I suspect that the resolution to this is to compare equality within some number of ULPs, but: 1) You still have the transitivity problem and 2) This is not my field of expertise, and there may be a more appropriate solution.

Re:GCC optimized code gives strange floating point results by SolarNet on Friday March 03, 2017 @03:51PM (#13786394)
> -sigma < x < 0 < y < sigma, abs(x - y) > sigma

This statement works fine. If the numbers are farther than sigma apart then `abs(x - y) > sigma` is true as it should be. It's not distance to 0, it's distance from each other related to 0 that matters.

> There are also problems with granularity. Suppose x and y are both much, much larger than sigma

This is part of the same problem. You have to choose a maximum acceptable value. And ensure you don't overflow it, and then you can choose a sigma based on that maximum value such that the difference between any two numbers never exceeds sigma. In practice you already have a maximum value for your domain that the simulation should never exceed or it means it is incorrect anyway.