/** * Returns {@code true} if {@code a} and {@code b} are nearly equal. Specifically, it checks whether the * {@link #relativeDifference(float, float) relative difference} of the two numbers is less than {@code maxRelDiff}. * * @param a first number. * @param b second number. * @param maxRelDiff the maximum {@link #relativeDifference relative difference} the two numbers may have. * @return {@code true} if {@code a} and {@code b} are nearly equal. */ public static boolean nearlyEquals(float a, float b, float maxRelDiff) { return relativeDifference(a, b) < maxRelDiff; }
/** Same as {@link #nearlyEquals(float, float, float)}, but for doubles. */ public static boolean nearlyEquals(double a, double b, double maxRelDiff) { return relativeDifference(a, b) < maxRelDiff; }
private String createNumericDataDiffMessage(DataType dt, String name, Number v1, Number v2, IndexIterator iter) { return String.format(" DIFF %s %s: %s != %s; count = %s, absDiff = %s, relDiff = %s %n", dt, name, v1, v2, iter, Misc.absoluteDifference(v1.doubleValue(), v2.doubleValue()), Misc.relativeDifference(v1.doubleValue(), v2.doubleValue())); }