The documentation for Double.Equals contains a useful method
public static bool HasMinimalDifference(double value1, double value2, int units)
{
long lValue1 = BitConverter.DoubleToInt64Bits(value1);
long lValue2 = BitConverter.DoubleToInt64Bits(value2);
// If the signs are different, return false except for +0 and -0.
if ((lValue1 >> 63) != (lValue2 >> 63))
{
if (value1 == value2)
return true;
return false;
}
long diff = Math.Abs(lValue1 - lValue2);
if (diff <= (long)units)
return true;
return false;
}
which seems to be the recommended way of testing for the "equality" of two double values.
However, try as I might I cannot work out the purpose of the third argument, units. In the example given, a value of 1 is passed, and no other explanation for its existence is given.
Can anyone clarify this?