News for hackers. Stuff that matters.
Re:Weird compiler bug – Same code, different results by ojnabieoot on Friday January 29, 2021 @10:41PM (#25965785)
I think you made the wrong correction in the article:

> Update: Thanks to gus_massa and wiml @ HackerNews for pointing out I had used associative instead of commutative.... This means that floating point arithmetic is noncommutative [i]n that A + B != B + A.

Floating-point arithmetic is commutative, but not associative. So for floating-point numbers,

A + B = B + A always, but

A + (B + C) != (A + B) + C in many cases.

The problem comes about from significant digits and rounding - A + B might round up to 1, but B + C might round down to zero, etc. The point remains that the order in which you do things actually does matter in floating-point arithmetic, but it's the order you compute the "inner parentheses," not the actual order of numbers in (e.g.) the FPU registers.

Re:Weird compiler bug – Same code, different results by zaitanz on Saturday January 30, 2021 @01:42AM (#25966840)
Thank you for your reply. I'm going to just lift your explanation as it's much better than my own.