Can someone point towards (or show) some good general floating point comparison functions in C# for comparing floating point values? I want to implement functions for IsEqual, IsGreater an IsLess. I also only really care about doubles not floats.
This is the best I've found so far for an IsEqual function.
EDIT: This is junk don't use it. See the accepted answer below.
public static bool IsEqual(this double a, double b, double epsilon)
{
if ((a == 0) && (b == 0))
return true;
else if (double.IsNaN(a) || double.IsNaN(b))
return false;
else if (double.IsPositiveInfinity(a))
return double.IsPositiveInfinity(b);
else if (double.IsNegativeInfinity(a))
return double.IsNegativeInfinity(b);
else
return Math.Abs(a - b) <= Math.Abs(a * epsilon);
}