diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jogl/classes/com/jogamp/math/DoubleUtil.java | 40 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/math/FloatUtil.java | 8 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/jogl/classes/com/jogamp/math/DoubleUtil.java b/src/jogl/classes/com/jogamp/math/DoubleUtil.java index e9ccceb10..8f1e44cd0 100644 --- a/src/jogl/classes/com/jogamp/math/DoubleUtil.java +++ b/src/jogl/classes/com/jogamp/math/DoubleUtil.java @@ -149,7 +149,11 @@ public final class DoubleUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < <code>epsilon</code>. + * Returns true if both values are equal, i.e. their absolute delta < {@code epsilon} if 0 != {@code epsilon}, + * otherwise == {@code 0}. + * <p> + * {@code epsilon} is allowed to be {@code 0}. + * </p> * <p> * Implementation considers following corner cases: * <ul> @@ -161,7 +165,8 @@ public final class DoubleUtil { * @see #EPSILON */ public static boolean isEqual(final double a, final double b, final double epsilon) { - if ( Math.abs(a - b) < epsilon ) { + if( 0 == epsilon && Math.abs(a - b) == 0 || + 0 != epsilon && Math.abs(a - b) < epsilon ) { return true; } else { // Values are equal (Inf, Nan .. ) @@ -170,7 +175,7 @@ public final class DoubleUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. + * Returns true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. * <p> * Implementation considers following corner cases: * <ul> @@ -191,7 +196,7 @@ public final class DoubleUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. + * Returns true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. * <p> * Implementation does not consider corner cases like {@link #isEqual(float, float, float)}. * </p> @@ -202,7 +207,7 @@ public final class DoubleUtil { } /** - * Return true if both values are equal w/o regarding an epsilon. + * Returns true if both values are equal w/o regarding an epsilon. * <p> * Implementation considers following corner cases: * <ul> @@ -234,7 +239,11 @@ public final class DoubleUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < <code>epsilon</code>. + * Returns {@code -1}, {@code 0} or {@code 1} if {@code a} is less, equal or greater than {@code b}, + * taking {@code epsilon} into account for equality. + * <p> + * {@code epsilon} is allowed to be {@code 0}. + * </p> * <p> * Implementation considers following corner cases: * <ul> @@ -248,7 +257,8 @@ public final class DoubleUtil { * @see #EPSILON */ public static int compare(final double a, final double b, final double epsilon) { - if ( Math.abs(a - b) < epsilon ) { + if( 0 == epsilon && Math.abs(a - b) == 0 || + 0 != epsilon && Math.abs(a - b) < epsilon ) { return 0; } else { return compare(a, b); @@ -256,15 +266,25 @@ public final class DoubleUtil { } /** - * Return true if value is zero, i.e. it's absolute value < <code>epsilon</code>. + * Returns true if value is zero, i.e. it's absolute value < {@code epsilon} if 0 != {@code epsilon}, + * otherwise {@code 0 == a}. + * <p> + * {@code epsilon} is allowed to be {@code 0}. + * </p> + * <pre> + * return 0 == epsilon && 0 == a || 0 != epsilon && Math.abs(a) < epsilon + * </pre> + * @param a value to test + * @param epsilon optional positive epsilon value, maybe {@code 0} * @see #EPSILON */ public static boolean isZero(final double a, final double epsilon) { - return Math.abs(a) < epsilon; + return 0 == epsilon && a == 0 || + 0 != epsilon && Math.abs(a) < epsilon; } /** - * Return true if value is zero, i.e. it's absolute value < {@link #EPSILON}. + * Returns true if value is zero, i.e. it's absolute value < {@link #EPSILON}. * @see #EPSILON */ public static boolean isZero(final double a) { diff --git a/src/jogl/classes/com/jogamp/math/FloatUtil.java b/src/jogl/classes/com/jogamp/math/FloatUtil.java index 94182baec..4ca706457 100644 --- a/src/jogl/classes/com/jogamp/math/FloatUtil.java +++ b/src/jogl/classes/com/jogamp/math/FloatUtil.java @@ -1454,7 +1454,7 @@ public final class FloatUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. + * Returns true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. * <p> * Implementation considers following corner cases: * <ul> @@ -1475,7 +1475,7 @@ public final class FloatUtil { } /** - * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. + * Returns true if both values are equal, i.e. their absolute delta < {@link #EPSILON}. * <p> * Implementation does not consider corner cases like {@link #isEqual(float, float, float)}. * </p> @@ -1486,7 +1486,7 @@ public final class FloatUtil { } /** - * Return true if both values are equal w/o regarding an epsilon. + * Returns true if both values are equal w/o regarding an epsilon. * <p> * Implementation considers following corner cases: * <ul> @@ -1563,7 +1563,7 @@ public final class FloatUtil { } /** - * Return true if value is zero, i.e. it's absolute value < {@link #EPSILON}. + * Returns true if value is zero, i.e. it's absolute value < {@link #EPSILON}. * @see #EPSILON */ public static boolean isZero(final float a) { |