Tony Johansson
2016-05-10 15:18:06 UTC
Hello!
Can somebody tell we if this simple method hold for comparing two double for
nearly equality.
I have tried several example with this method and it seems to compare
correct.
I mean as long as the abs value between them is smallen then my epilon set
to 0.001 it seems to work fine.
I just want to know if somebody can tell me when this method should return
true but return false when comparing two double.
public static bool NearlyEqual(double a, double b, double epsilon)
{
if (Math.Abs(a-b) < epsilon)
{
return true;
}
return false;
}
//Tony
Can somebody tell we if this simple method hold for comparing two double for
nearly equality.
I have tried several example with this method and it seems to compare
correct.
I mean as long as the abs value between them is smallen then my epilon set
to 0.001 it seems to work fine.
I just want to know if somebody can tell me when this method should return
true but return false when comparing two double.
public static bool NearlyEqual(double a, double b, double epsilon)
{
if (Math.Abs(a-b) < epsilon)
{
return true;
}
return false;
}
//Tony