From c1f2e60e81b5d7ff81d3753de1eea8b969859075 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Fri, 29 Aug 2008 16:17:33 +0000 Subject: [PATCH] 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 --- src/java/org/apache/commons/math/geometry/Vector3D.java | 6 ++---- src/java/org/apache/commons/math/linear/RealMatrixImpl.java | 6 ++---- src/java/org/apache/commons/math/linear/RealVectorImpl.java | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/commons/math/geometry/Vector3D.java b/src/java/org/apache/commons/math/geometry/Vector3D.java index 44f71a2d3..ec4f2497a 100644 --- a/src/java/org/apache/commons/math/geometry/Vector3D.java +++ b/src/java/org/apache/commons/math/geometry/Vector3D.java @@ -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 diff --git a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java index 568dd4eea..c36c902a9 100644 --- a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -1192,8 +1192,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable { /** * Returns true iff object is a * RealMatrixImpl 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; } } diff --git a/src/java/org/apache/commons/math/linear/RealVectorImpl.java b/src/java/org/apache/commons/math/linear/RealVectorImpl.java index f30524676..53d6f7a5b 100644 --- a/src/java/org/apache/commons/math/linear/RealVectorImpl.java +++ b/src/java/org/apache/commons/math/linear/RealVectorImpl.java @@ -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; } }