title: Why does adding double.epsilon to a value result in the same value, perfectly equal?
body: <p>I have a unit test, testing boundaries:</p>
  
  <pre><code>[TestMethod]
  [ExpectedException(typeof(ArgumentOutOfRangeException))]
  public void CreateExtent_InvalidTop_ShouldThrowArgumentOutOfRangeException()
  {
      var invalidTop = 90.0 + Double.Epsilon;
      new Extent(invalidTop, 0.0, 0.0, 0.0);
  }
  
  public static readonly double MAX_LAT = 90.0;
  
  public Extent(double top, double right, double bottom, double left)
  {
      if (top &gt; GeoConstants.MAX_LAT)
          throw new ArgumentOutOfRangeException("top"); // not hit
  }
  </code></pre>
  
  <p>I thought I'd just tip the 90.0 over the edge by adding the minimum possible positive double to it, but now the exception is not thrown, any idea why?</p>
  
  <p>When debugging, I see top as coming in as 90, when it should be 90.00000000.... something.</p>
  
  <p><strong>EDIT:</strong>
  I should have thought a bit harder, <code>90+Double.Epsilon</code> will lose its resolution. Seems the best way to go is do some bit shifting.</p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <pre><code>[TestMethod]
  [ExpectedException(typeof(ArgumentOutOfRangeException))]
  public void CreateExtent_InvalidTop_ShouldThrowArgumentOutOfRangeException()
  {
      var invalidTop = Utility.IncrementTiny(90); // 90.000000000000014
      // var sameAsEpsilon = Utility.IncrementTiny(0);
      new Extent(invalidTop, 0, 0, 0);
  }
  
  /// &lt;summary&gt;
  /// Increment a double-precision number by the smallest amount possible
  /// &lt;/summary&gt;
  /// &lt;param name="number"&gt;double-precision number&lt;/param&gt;
  /// &lt;returns&gt;incremented number&lt;/returns&gt;
  public static double IncrementTiny(double number)
  {
      #region SANITY CHECKS
      if (Double.IsNaN(number) || Double.IsInfinity(number))
          throw new ArgumentOutOfRangeException("number");
      #endregion
  
      var bits = BitConverter.DoubleToInt64Bits(number);
  
      // if negative then go opposite way
      if (number &gt; 0)
          return BitConverter.Int64BitsToDouble(bits + 1);
      else if (number &lt; 0)
          return BitConverter.Int64BitsToDouble(bits - 1);
      else
          return Double.Epsilon;
  }
  
  /// &lt;summary&gt;
  /// Decrement a double-precision number by the smallest amount possible
  /// &lt;/summary&gt;
  /// &lt;param name="number"&gt;double-precision number&lt;/param&gt;
  /// &lt;returns&gt;decremented number&lt;/returns&gt;
  public static double DecrementTiny(double number)
  {
      #region SANITY CHECKS
      if (Double.IsNaN(number) || Double.IsInfinity(number))
          throw new ArgumentOutOfRangeException("number");
      #endregion
  
      var bits = BitConverter.DoubleToInt64Bits(number);
  
      // if negative then go opposite way
      if (number &gt; 0)
          return BitConverter.Int64BitsToDouble(bits - 1);
      else if (number &lt; 0)
          return BitConverter.Int64BitsToDouble(bits + 1);
      else
          return 0 - Double.Epsilon;
  }
  </code></pre>
  
  <p>This does the job.</p>