I think it’s equal zero in this case. I’d have to look up the IEEE specification to make sure. AFAIK it’s just not guaranteed for any numbers and depends on the floating point implementation. A general rule of thumb for programmers is not to use ‘equal’ with floating point numbers.
Also 1-1 ≠ 0
Are you sure? I’ve never seen that inequality before.
Edit: and at least python agrees with me
I think it’s equal zero in this case. I’d have to look up the IEEE specification to make sure. AFAIK it’s just not guaranteed for any numbers and depends on the floating point implementation. A general rule of thumb for programmers is not to use ‘equal’ with floating point numbers.
The example is wrong, because they used
1.0
.But in general
x-x
does not have to equal0
, that is true. I’m pretty sureNan
andinfinity
would yield not0.0
, butNan
instead.And if you reach x with two different calculations, e.g.
x1 = a - b - c
andx2 = a - c - b
it is certainly not guaranteed thatx1 - x2 == 0.0
It does.
x-x == 0
is true unlessx
is NaN or infinity.Positive or negative zero?