News for hackers. Stuff that matters.
Re:Weird compiler bug – Same code, different results by gus_massa on Friday January 29, 2021 @04:53PM (#25963150)
> This means that floating point arithmetic is non-associative. In that A + B != B + A.

The equation is the commutative property, not associative. IIRC addition in IEEE-754 is commutative.

The property that fails is (A+B)+C = A+(B+C).

Re:Weird compiler bug – Same code, different results by zaitanz on Friday January 29, 2021 @06:12PM (#25964071)
Op Here. Yes you are correct. Been very sleep derived when I wrote this (newborns eh). I'll update this.

I didn't want to go too far into the background of floating point math in the post as it wasn't ultimately the issue, just something I was mindful of.

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.