/** * Tests if two {@code double} values are equal within the specified * proportional tolerance. This is equivalent to: * <pre><code> * double absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2)); * boolean b = aequal(x1, x2, absTol); * </code></pre> * * @param x1 first value * @param x2 second value * @param propTol proportional tolerance between 0 and 1 * * @return {@code true} if equal; {@code false} otherwise */ public static boolean pequal(double x1, double x2, double propTol) { if (aequal(x1, x2)) { return true; } int comp = acompare(Math.abs(x1), Math.abs(x2)); double absTol = Math.abs(propTol) * (comp > 0 ? x1 : x2); return aequal(x1, x2, absTol); }
/** * Tests if two {@code float} values are equal within the default tolerance. * This is equivalent to {@code dzero(x1 - x2)}. * * @param x1 first value * @param x2 second value * * @return {@code true} if equal; {@code false} otherwise */ public static boolean aequal(float x1, float x2) { return isZero(x1 - x2); }
/** * Tests if a value should be treated as NODATA. * Values that are NaN, infinite or equal to Double.MAX_VALUE * are always treated as NODATA. * * @param value the value to test * * @return {@code true} if a NODATA value; {@code false} otherwise */ private boolean isNoData(double value) { if (Double.isNaN(value) || Double.isInfinite(value) || Double.compare(value, Double.MAX_VALUE) == 0) { return true; } for (Double d : noDataNumbers) { if (CompareOp.aequal(value, d)) { return true; } } for (Range r : noDataRanges) { if (r.contains(value)) { return true; } } return false; } }
dist2 = x * x + y2; if (CompareOp.acompare(r2, dist2) >= 0) { switch (type) { case BINARY:
/** * Tests if two {@code float} values are equal within the specified * proportional tolerance. This is equivalent to: * <pre><code> * float absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2)); * boolean b = aequal(x1, x2, absTol); * </code></pre> * * @param x1 first value * @param x2 second value * @param propTol proportional tolerance between 0 and 1 * * @return {@code true} if equal; {@code false} otherwise */ public static boolean pequal(float x1, float x2, float propTol) { if (aequal(x1, x2)) { return true; } int comp = acompare(Math.abs(x1), Math.abs(x2)); double absTol = Math.abs(propTol) * (comp > 0 ? x1 : x2); return aequal(x1, x2, absTol); }
if (CompareOp.aequal(curVal, list.get(i))) { curFreq++ ; } else {
/** * Tests if two {@code double} values are equal within the default tolerance. * This is equivalent to {@code dzero(x1 - x2)}. * * @param x1 first value * @param x2 second value * * @return {@code true} if equal; {@code false} otherwise */ public static boolean aequal(double x1, double x2) { return isZero(x1 - x2); }
/** * Compares two {@code double} values using the specified proportional * tolerance. This is equivalent to: * <pre><code> * double absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2)); * int comp = acompare(x1, x2, absTol); * </code></pre> * * @param x1 first value * @param x2 second value * @param propTol proportional tolerance between 0 and 1 * * @return a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; * a value greater than 0 if x1 is greater than x2 */ public static int pcompare(double x1, double x2, double propTol) { if (aequal(x1, x2)) { return 0; } int comp = acompare(Math.abs(x1), Math.abs(x2)); double absTol = Math.abs(propTol) * (comp > 0 ? x1 : x2); return acompare(x1, x2, absTol); }
return CompareOp.acompare(Math.abs(val - refValue), tolerance) <= 0;
/** * Tests if two {@code double} values are equal within the specified tolerance. * This is equivalent to {@code dzero(x1 - x2, tol)}. * Note that performance reasons, {@code tol} is <strong>assumed</strong> * to be positive, ie. this is not checked. * * @param x1 first value * @param x2 second value * @param tol comparison tolerance * * @return {@code true} if equal; {@code false} otherwise */ public static boolean aequal(double x1, double x2, double tol) { return isZero(x1 - x2, tol); }
/** * Compares two {@code float} values using the specified proportional * tolerance. This is equivalent to: * <pre><code> * float absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2)); * int comp = acompare(x1, x2, absTol); * </code></pre> * * @param x1 first value * @param x2 second value * @param propTol proportional tolerance between 0 and 1 * * @return a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; * a value greater than 0 if x1 is greater than x2 */ public static int pcompare(float x1, float x2, float propTol) { if (aequal(x1, x2)) { return 0; } int comp = acompare(Math.abs(x1), Math.abs(x2)); double absTol = Math.abs(propTol) * (comp > 0 ? x1 : x2); return acompare(x1, x2, absTol); }
/** * Tests if two {@code float} values are equal within the specified tolerance. * This is equivalent to {@code dzero(x1 - x2, tol)}. * Note that performance reasons, {@code tol} is <strong>assumed</strong> * to be positive, ie. this is not checked. * * @param x1 first value * @param x2 second value * @param tol comparison tolerance * * @return {@code true} if equal; {@code false} otherwise */ public static boolean aequal(float x1, float x2, float tol) { return isZero(x1 - x2, tol); }
/** * Compares two {@code float} values using the default tolerance. * * @param x1 first value * @param x2 second value * * @return a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; * a value greater than 0 if x1 is greater than x2 */ public static int acompare(float x1, float x2) { if (isZero(x1 - x2)) { return 0; } else { return Float.compare(x1, x2); } }
/** * Compares two {@code double} values using the default tolerance. * * @param x1 first value * @param x2 second value * * @return a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; * a value greater than 0 if x1 is greater than x2 */ public static int acompare(double x1, double x2) { if (isZero(x1 - x2)) { return 0; } else { return Double.compare(x1, x2); } }
/** * Compares two {@code float} values using the specified tolerance. * Note that performance reasons, {@code tol} is <strong>assumed</strong> * to be positive, ie. this is not checked. * * @param x1 first value * @param x2 second value * @param tol comparison tolerance * * @return a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; * a value greater than 0 if x1 is greater than x2 */ public static int acompare(float x1, float x2, float tol) { if (isZero(x1 - x2, tol)) { return 0; } else { return Float.compare(x1, x2); } }