title: When is (x==(x+y)-y) or (x==(x-y)+y) guaranteed for IEEE floats?
body: <p>In C or another language which uses IEEE floats, I have two variables <code>x</code> and <code>y</code> which are both guaranteed to be finite, non-NaN, basically normal numbers.</p>
  
  <p>I have some code which assumes, in essence, that the following code has no effect:</p>
  
  <pre><code>float x = get_x ();
  float y = get_y ();
  
  float old_x = x;
  x += y;
  x -= y;
  assert (old_x == x);
  x -= y;
  x += y;
  assert (old_x == x);
  </code></pre>
  
  <p>I know that this will be true for certain classes of values, i.e. those which do not have "many" significant figures in the mantissa, but I would like to be clear about the edge cases.</p>
  
  <p>For example, the binary expression of <code>1.3</code> will have significant figures all the way down the mantissa, and so will <code>1.7</code>, and I should not assume that <code>1.3+1.7==3</code> exactly, but can I assume that if I add such numbers together and then subtract them, or vice versa, I will get the first value back again?</p>
  
  <p>What are the formal edge conditions for this?</p>