Changed the equals() methods from RealMatrixImpl, RealVectorImpl and Vector3D

so that they consider +0 and -0 are equal, as required by IEEE-754 standard.
These were bugs similar to MATH-221 for Complex.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@690314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-08-29 16:17:33 +00:00
parent 94cf29c4e3
commit c1f2e60e81
3 changed files with 5 additions and 10 deletions

View File

@ -403,14 +403,12 @@ public class Vector3D
try {
Vector3D rhs = (Vector3D)other;
final Vector3D rhs = (Vector3D)other;
if (rhs.isNaN()) {
return this.isNaN();
}
return (Double.doubleToRawLongBits(x) == Double.doubleToRawLongBits(rhs.x)) &&
(Double.doubleToRawLongBits(y) == Double.doubleToRawLongBits(rhs.y)) &&
(Double.doubleToRawLongBits(z) == Double.doubleToRawLongBits(rhs.z));
return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
} catch (ClassCastException ex) {
// ignore exception

View File

@ -1192,8 +1192,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
/**
* Returns true iff <code>object</code> is a
* <code>RealMatrixImpl</code> instance with the same dimensions as this
* and all corresponding matrix entries are equal. Corresponding entries
* are compared using {@link java.lang.Double#doubleToLongBits(double)}
* and all corresponding matrix entries are equal.
*
* @param object the object to test equality against.
* @return true if object equals this
@ -1214,8 +1213,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
for (int row = 0; row < nRows; row++) {
final double[] dataRow = data[row];
for (int col = 0; col < nCols; col++) {
if (Double.doubleToLongBits(dataRow[col]) !=
Double.doubleToLongBits(m.getEntry(row, col))) {
if (dataRow[col] != m.getEntry(row, col)) {
return false;
}
}

View File

@ -1266,8 +1266,7 @@ public class RealVectorImpl implements RealVector, Serializable {
}
for (int i = 0; i < data.length; ++i) {
if (Double.doubleToRawLongBits(data[i]) !=
Double.doubleToRawLongBits(rhs.getEntry(i))) {
if (data[i] != rhs.getEntry(i)) {
return false;
}
}