If you reflect over WindowsBase.dll > MS.Internal.DoubleUtil.AreClose(...)
you'll get the following code:
public static bool AreClose(double value1, double value2)
{
if (value1 == value2)
{
return true;
}
double num2 = ((Math.Abs(value1) + Math.Abs(value2)) + 10.0) * 2.2204460492503131E-16;
double num = value1 - value2;
return ((-num2 < num) && (num2 > num));
}
I'm trying to understand two different things:
Where did they come up with the formula for num2? I guess I just don't understand the significance of first adding the value of
10.0
and secondly multiplying all the results by this the number2.2204460492503131E-16
. Anyone know why this is the formula used?What is the point of the return statement there? It seems that by default if num2 greater than num than the negated value of num2 should be less than num. Maybe I'm missing something here, but it seems redundant. To me it's like checking if 5 is larger than 3 and if -5 is less than 3 (as an example).