Is there a floating point value of x, for which x-x == 0 is false?

Posted by Andrew Walker on Stack Overflow See other posts from Stack Overflow or by Andrew Walker
Published on 2010-04-21T21:19:01Z Indexed on 2010/04/21 21:23 UTC
Read the original article Hit count: 315

In most cases, I understand that a floating point comparison test should be implemented using over a range of values (abs(x-y) < epsilon), but does self subtraction imply that the result will be zero?

// can the assertion be triggered?
float x = //?;
assert( x-x == 0 )

My guess is that nan/inf might be special cases, but I'm more interested in what happens for simple values.

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++