title: Estimate error in floating point calculations
body: <p>One important property of IEEE floating-point math that rounding causes "errors" in calculations due to the limited number of bits and the base-2 format.</p>
  
  <p>E.g. in C#:</p>
  
  <pre><code>(Math.PI * 1e20 / 1e20) == Math.PI; // false
  </code></pre>
  
  <p>Is there a way to determine the magnitude of the error of those operations? .NET exposes the <a href="http://msdn.microsoft.com/en-us/library/system.double.epsilon.aspx" rel="nofollow"><code>Double.Epsilon</code></a> field that give the smallest significant value greater than zero, but that's not relevant for comparing non-zero numbers.</p>
  
  <p>EDIT: I'm not asking for a way to <em>exactly</em> compute the error, I'm just trying to find a way to estimate its magnitude.</p>
  
  <p>For example (again, in C#):</p>
  
  <pre><code>(1e20 + 1e3) == 1e20; // true
  (1e20 + 1e4) == 1e20; // false
  </code></pre>
  
  <p>So the error of the operation <code>1e20 + X</code> appears to be approximately 1e3, which makes sense because <code>doubles</code> have up to 17 digits of decimal precision.</p>