Hacker News new | ask | show | jobs
by zaitanz 1962 days ago
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.

1 comments

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.

Thank you for your reply. I'm going to just lift your explanation as it's much better than my own.