guava/src/com/google/common/math/DoubleMath.java
public static boolean fuzzyEquals(double a, double b, double tolerance) {
    MathPreconditions.checkNonNegative("tolerance", tolerance);
    return Math.copySign(a - b, 1.0) <= tolerance
        // copySign(x, 1.0) is a branch-free version of abs(x), but with different NaN semantics
        || (a == b) // needed to ensure that infinities equal themselves
        || (Double.isNaN(a) && Double.isNaN(b));
  }
public static boolean fuzzyEquals(double a, double b, double tolerance) {
    MathPreconditions.checkNonNegative("tolerance", tolerance);
    return Math.copySign(a - b, 1.0) <= tolerance
        // copySign(x, 1.0) is a branch-free version of abs(x), but with different NaN semantics
        || (a == b) // needed to ensure that infinities equal themselves
        || (Double.isNaN(a) && Double.isNaN(b));
  }
Returns {@code true} if {@code a} and {@code b} are within {@code tolerance} of each other.

<p>Technically speaking, this is equivalent to {@code Math.abs(a - b) <= tolerance ||
Double.valueOf(a).equals(Double.valueOf(b))}.

<p>Notable special cases include:

<ul>
<li>All NaNs are fuzzily equal.
<li>If {@code a == b}, then {@code a} and {@code b} are always fuzzily equal.
<li>Positive and negative zero are always fuzzily equal.
<li>If {@code tolerance} is zero, and neither {@code a} nor {@code b} is NaN, then {@code a}
and {@code b} are fuzzily equal if and only if {@code a == b}.
<li>With {@link Double#POSITIVE_INFINITY} tolerance, all non-NaN values are fuzzily equal.
<li>With finite tolerance, {@code Double.POSITIVE_INFINITY} and {@code
Double.NEGATIVE_INFINITY} are fuzzily equal only to themselves.
</ul>

<p>This is reflexive and symmetric, but <em>not</em> transitive, so it is <em>not</em> an
equivalence relation and <em>not</em> suitable for use in {@link Object#equals}
implementations.

@throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN
@since 13.0