fix: some logic error on float.ApproximatelyEquals

This commit is contained in:
2026-04-18 23:18:21 +02:00
parent ce3e46948f
commit 8cb0e81ed0

View File

@@ -9,14 +9,7 @@ public static class FloatExtensions
if (a == b) if (a == b)
return true; return true;
const float floatNormal = (1 << 23) * float.Epsilon;
float absA = Math.Abs(a);
float absB = Math.Abs(b);
float diff = Math.Abs(a - b); float diff = Math.Abs(a - b);
return diff < epsilon;
if (a == 0.0f || b == 0.0f || diff < floatNormal)
return diff < (epsilon * floatNormal);
return diff / Math.Min(absA + absB, float.MaxValue) < epsilon;
} }
} }