Surprising arithmetic

There is no double precision number between \(1\) and \(1+\epsilon_\text{mach}\). Thus the following difference is zero despite its appearance.

e = eps()/2
(1.0 + e) - 1.0

However, the spacing between floats in \([1.2,1)\) is \(\text{mach}/2\), so both \(1-\epsilon_\text{mach}/2\) and its negative are represented exactly:

1.0 + (e - 1.0)

This is now the “correct” result. But we have found a rather shocking breakdown of the associative law of addition!