MCPcopy Create free account
hub / github.com/antlr/codebuff / fuzzyEquals

Method fuzzyEquals

output/java_guava/1.4.18/DoubleMath.java:355–361  ·  view source on GitHub ↗

Returns true if a and b are within tolerance of each other. Technically speaking, this is equivalent to Math.abs(a - b) <= tolerance || Double.valueOf(a).equals(Double.valueOf(b)). Notable special cases include: All NaNs are fuzzily equal. <li

(double a, double b, double tolerance)

Source from the content-addressed store, hash-verified

353 */
354
355 public static boolean fuzzyEquals(double a, double b, double tolerance) {
356 MathPreconditions.checkNonNegative("tolerance", tolerance);
357 return Math.copySign(a - b, 1.0) <= tolerance
358 // copySign(x, 1.0) is a branch-free version of abs(x), but with different NaN semantics
359 || (a == b) // needed to ensure that infinities equal themselves
360 || (Double.isNaN(a) && Double.isNaN(b));
361 }
362
363 /**
364 * Compares {@code a} and {@code b} "fuzzily," with a tolerance for nearly-equal values.

Callers 1

fuzzyCompareMethod · 0.95

Calls 1

checkNonNegativeMethod · 0.95

Tested by

no test coverage detected