News for hackers. Stuff that matters.
Re:John Gustafson’s crusade to replace floating point with s... by martinpw on Tuesday July 09, 2019 @01:19AM (#20389200)
> On old x86 systems, the x87 registers were 80-bits and the bottom bits were undefined. You could theoretically have a 1-bit difference on some results

I spent a long time once debugging an issue arising from this. Code was basically:

  double x = y;
  [...]
  if (x>y) fail;
Nothing in between the assignment and the check changed the value of x or y, yet the check triggered the fail condition. Turned out to be that one of the value stayed in the 80 bit x87 register and one was written to RAM as a 64 bit value, then loaded back into an x87 register for the check, resulting in the inequality. Running in a debugger wrote both values out of the registers before the check, making the problem unreproducible.
Re:John Gustafson’s crusade to replace floating point with s... by desdiv on Tuesday July 09, 2019 @02:19AM (#20389408)
Yes, that's a hard bug to catch, but if the mantra of "every floating point comparison must use a context-appropriate epsilon" is followed, then it wouldn't have happened in the first place.
Re:John Gustafson’s crusade to replace floating point with s... by stkdump on Tuesday July 09, 2019 @08:00AM (#20390910)
I hate that mantra, as it produced more bugs and inaccuracies in the code I have to work with than necessary. Actually you should be able to rely on the equality of a value with its copy no matter what. We are past the FPU days, so I think we can let go of these mindless epsilons sprinkled over the code.

(Even during the FPU days, every ; should have rounded each value to the size of the variables, unless you use a special compiler switch to make FP math faster)

Re:John Gustafson’s crusade to replace floating point with s... by martinpw on Tuesday July 09, 2019 @02:32AM (#20389455)
Absolutely, and the fix involved adding a tolerance check. Not my code, I was the new guy at the time, and my job was trying to fix the bugs nobody else wanted to deal with...
Re:John Gustafson’s crusade to replace floating point with s... by pvg on Tuesday July 09, 2019 @01:51AM (#20389296)
Nothing in between the assignment and the check changed the value of x or y

What was the check for?

Re:John Gustafson’s crusade to replace floating point with s... by martinpw on Tuesday July 09, 2019 @02:31AM (#20389449)
There was code in between that could have changed the value, but it was never triggered in the bug case.
Re:John Gustafson’s crusade to replace floating point with s... by pvg on Tuesday July 09, 2019 @03:47AM (#20389740)
Ah yeah, that makes sense. Relying on FP equality should always make one's eye twitch a little but this is a neat way of hiding it.