diff --git a/src/main/java/org/apache/commons/math/util/MathUtils.java b/src/main/java/org/apache/commons/math/util/MathUtils.java
index 887dc66a2..ab0fe3358 100644
--- a/src/main/java/org/apache/commons/math/util/MathUtils.java
+++ b/src/main/java/org/apache/commons/math/util/MathUtils.java
@@ -407,20 +407,14 @@ public final class MathUtils {
/**
* Returns true iff they are equal as defined by
- * {@link #equals(double,double,int) this method}.
+ * {@link #equals(double,double,int) equals(x, y, 1)}.
*
* @param x first value
* @param y second value
* @return {@code true} if the values are equal.
- * @deprecated This method considers that {@code NaN == NaN}. In release
- * 3.0, the semantics will change in order to comply with IEEE754 where it
- * is specified that {@code NaN != NaN}.
- * New methods have been added for those cases wher the old semantics is
- * useful (see e.g. {@link #equalsIncludingNaN(double,double)
- * equalsIncludingNaN}.
*/
public static boolean equals(double x, double y) {
- return (Double.isNaN(x) && Double.isNaN(y)) || x == y;
+ return equals(x, y, 1);
}
/**
@@ -524,12 +518,6 @@ public final class MathUtils {
* @param y second array
* @return true if the values are both null or have same dimension
* and equal elements.
- * @deprecated This method considers that {@code NaN == NaN}. In release
- * 3.0, the semantics will change in order to comply with IEEE754 where it
- * is specified that {@code NaN != NaN}.
- * New methods have been added for those cases wher the old semantics is
- * useful (see e.g. {@link #equalsIncludingNaN(double[],double[])
- * equalsIncludingNaN}.
*/
public static boolean equals(double[] x, double[] y) {
if ((x == null) || (y == null)) {
@@ -1101,29 +1089,6 @@ public final class MathUtils {
return ret;
}
- /**
- * Get the next machine representable number after a number, moving
- * in the direction of another number.
- *
- * If direction
is greater than or equal tod
,
- * the smallest machine representable number strictly greater than
- * d
is returned; otherwise the largest representable number
- * strictly less than d
is returned.
- *
- * If d
is NaN or Infinite, it is returned unchanged.
- *
- * @param d base number
- * @param direction (the only important thing is whether
- * direction is greater or smaller than d)
- * @return the next machine representable number in the specified direction
- * @since 1.2
- * @deprecated as of 2.2, replaced by {@link FastMath#nextAfter(double, double)}
- */
- @Deprecated
- public static double nextAfter(double d, double direction) {
- return FastMath.nextAfter(d, direction);
- }
-
/**
* Scale a number by 2scaleFactor.
* If d
is 0 or NaN or Infinite, it is returned unchanged.
@@ -1318,23 +1283,23 @@ public final class MathUtils {
switch (roundingMethod) {
case BigDecimal.ROUND_CEILING :
if (sign == -1) {
- unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
} else {
- unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
}
break;
case BigDecimal.ROUND_DOWN :
- unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
break;
case BigDecimal.ROUND_FLOOR :
if (sign == -1) {
- unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
} else {
- unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
}
break;
case BigDecimal.ROUND_HALF_DOWN : {
- unscaled = nextAfter(unscaled, Double.NEGATIVE_INFINITY);
+ unscaled = FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY);
double fraction = unscaled - FastMath.floor(unscaled);
if (fraction > 0.5) {
unscaled = FastMath.ceil(unscaled);
@@ -1361,7 +1326,7 @@ public final class MathUtils {
break;
}
case BigDecimal.ROUND_HALF_UP : {
- unscaled = nextAfter(unscaled, Double.POSITIVE_INFINITY);
+ unscaled = FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY);
double fraction = unscaled - FastMath.floor(unscaled);
if (fraction >= 0.5) {
unscaled = FastMath.ceil(unscaled);
@@ -1376,7 +1341,7 @@ public final class MathUtils {
}
break;
case BigDecimal.ROUND_UP :
- unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
break;
default :
throw MathRuntimeException.createIllegalArgumentException(
@@ -1904,24 +1869,6 @@ public final class MathUtils {
checkOrder(val, OrderDirection.INCREASING, true);
}
- /**
- * Checks that the given array is sorted.
- *
- * @param val Values
- * @param dir Order direction (-1 for decreasing, 1 for increasing)
- * @param strict Whether the order should be strict
- * @throws NonMonotonousSequenceException if the array is not sorted.
- * @deprecated as of 2.2 (please use the new {@link #checkOrder(double[],OrderDirection,boolean)
- * checkOrder} method). To be removed in 3.0.
- */
- public static void checkOrder(double[] val, int dir, boolean strict) {
- if (dir > 0) {
- checkOrder(val, OrderDirection.INCREASING, strict);
- } else {
- checkOrder(val, OrderDirection.DECREASING, strict);
- }
- }
-
/**
* Returns the Cartesian norm (2-norm), handling both overflow and underflow.
* Translation of the minpack enorm subroutine.
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index 0ae742cfb..bf6d41165 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -52,6 +52,14 @@ The type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces!
-->
+
+ Modified semantics: "equals" methods now consider that NaNs are not
+ equal (compliant with IEEE754).
+ Also, two adjacent floating point numbers are considered equal (this
+ is consistent with the fact that all real numbers between them can be
+ represented by either of the two). One consequence of that is that
+ "equals" is not transitive.
+
Removed methods referring to the concept of "iteration".
Removed interface methods to access the number of evaluations of the
diff --git a/src/test/java/org/apache/commons/math/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
index a2dc70b96..fa42e84ba 100644
--- a/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
+++ b/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
@@ -447,16 +447,18 @@ public final class MathUtilsTest extends TestCase {
assertFalse(MathUtils.equals(new double[] { 1d }, new double[0]));
assertTrue(MathUtils.equals(new double[] { 1d }, new double[] { 1d }));
assertTrue(MathUtils.equals(new double[] {
- Double.NaN, Double.POSITIVE_INFINITY,
+ Double.POSITIVE_INFINITY,
Double.NEGATIVE_INFINITY, 1d, 0d
}, new double[] {
- Double.NaN, Double.POSITIVE_INFINITY,
+ Double.POSITIVE_INFINITY,
Double.NEGATIVE_INFINITY, 1d, 0d
}));
+ assertFalse(MathUtils.equals(new double[] { Double.NaN },
+ new double[] { Double.NaN }));
assertFalse(MathUtils.equals(new double[] { Double.POSITIVE_INFINITY },
new double[] { Double.NEGATIVE_INFINITY }));
assertFalse(MathUtils.equals(new double[] { 1d },
- new double[] { FastMath.nextAfter(1d, 2d) }));
+ new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
}