public static void Main()
if(val == 0) throw new Exception("Comparison value got rounded to zero");
var equal = Equal(0, val);
Console.WriteLine(equal);
Console.WriteLine(float.MinValue);
public static bool Equal(double leftValue, double rightValue, double epsilon = 0.00001)
if (leftValue == rightValue)
var diff = Math.Abs(leftValue - rightValue);
if (leftValue == 0f || rightValue == 0f || diff < float.MinValue)
return diff < epsilon * float.MinValue;
var absLeft = Math.Abs(leftValue);
var absRight = Math.Abs(rightValue);
return diff / Math.Min(absLeft + absRight, float.MaxValue) < epsilon;