Java Utililty Methods Double Number Almost Equal

List of utility methods to do Double Number Almost Equal

Description

The list of methods to do Double Number Almost Equal are organized into topic(s).

Method

booleanalmost(double a, double b, double prec)
almost
return Math.abs(a - b) / Math.abs(a + b) <= prec || (almostZero(a) && almostZero(b));
booleanalmostEqual(double a, double b)
almost Equal
if (Math.abs(a - b) <= ABSOLUTE_EPSILON)
    return true;
double a1 = a * (1 - RELATIVE_EPSILON);
double a2 = a * (1 + RELATIVE_EPSILON);
if ((a1 <= b) && (b <= a2))
    return true;
if ((a2 <= b) && (b <= a1))
    return true;
...
booleanalmostEqual(double a, double b, double delta)
Check whether two floating point values match with a given precision.
return Math.abs(a - b) <= delta;
booleanalmostEqual(double[][] a, double[][] b, double delta)
almost Equal
if (a.length != b.length)
    return false;
boolean r = true;
loop1: for (int i = 0; i < a.length; i++) {
    for (int j = 0; j < a[i].length; j++) {
        double d = Math.abs((a[i][j] - b[i][j]) / b[i][j]);
        if (d > delta) {
            r = false;
...
booleanalmostEqual(final double aDouble, final double otherDouble)
almost Equal
return Math.abs(aDouble - otherDouble) < 0.001;
booleanalmostEquals(double d1, double d2)
almost Equals
return (d1 == 0 && d2 == 0) || Math.abs((d1 / d2) - 1) < EPSILON;
booleanalmostEquals(double d1, double d2, double epsilon)
almost Equals
return Math.abs(d1 - d2) < epsilon;
booleanalmostEquals(double d1, double d2, double threshold)
almost Equals
if (d1 >= d2 - threshold && d1 <= d2 + threshold) {
    return true;
} else {
    return false;