Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Math.Abs(a - b) < some_epsilon // `a` is roughly equivalent to `b`
- public static bool DoubleEquality(double a, double b)
- {
- const double epsilonValue = 1e-15;
- if (double.IsNaN(a))
- return double.IsNaN(b);
- else if (double.IsInfinity(a))
- return double.IsInfinity(b);
- else if (a == 0)
- return b == 0;
- else
- return Math.Abs(a - b) <= Math.Abs(a * epsilonValue);
- }
Add Comment
Please, Sign In to add comment