Class AlmostEqualDouble

java.lang.Object
com.io7m.jequality.AlmostEqualDouble

@EqualityReference public final class AlmostEqualDouble extends Object

Better floating point comparisons.

See Comparing floating point numbers 2012.

  • Method Details

    • almostEqual

      public static boolean almostEqual(AlmostEqualDouble.ContextRelative context, double x, double y)

      Compare the floating point numbers x and y using the context context.

      Essentially, given diff = abs(x - y), if diff <= context.getMaxRelativeDifference() * max(abs(x), abs(y)) , then x and y can be considered to be close together.

      See the article mentioned at the top of this article for suggested absolute and relative epsilon values: There are no values that work well for all possible inputs.

      Parameters:
      context - The equality context
      x - The left parameter
      y - The right parameter
      Returns:
      true if x and y are almost equal