You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/08/29 17:46:23 UTC
svn commit: r690308 - in /commons/proper/math/branches/MATH_2_0/src:
java/org/apache/commons/math/complex/Complex.java site/xdoc/changes.xml
test/org/apache/commons/math/complex/ComplexTest.java
Author: luc
Date: Fri Aug 29 08:46:22 2008
New Revision: 690308
URL: http://svn.apache.org/viewvc?rev=690308&view=rev
Log:
Changed the Complex.equals() method so that it considers +0 and -0 are equal,
as required by IEEE-754 standard.
JIRA: MATH-221
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java
commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java
Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java?rev=690308&r1=690307&r2=690308&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java Fri Aug 29 08:46:22 2008
@@ -255,10 +255,7 @@
if (rhs.isNaN()) {
ret = this.isNaN();
} else {
- ret = (Double.doubleToRawLongBits(real) ==
- Double.doubleToRawLongBits(rhs.getReal())) &&
- (Double.doubleToRawLongBits(imaginary) ==
- Double.doubleToRawLongBits(rhs.getImaginary()));
+ ret = (real == rhs.real) && (imaginary == rhs.imaginary);
}
} catch (ClassCastException ex) {
// ignore exception
Modified: commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml?rev=690308&r1=690307&r2=690308&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml Fri Aug 29 08:46:22 2008
@@ -39,6 +39,10 @@
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
+ <action dev="luc" type="fix" issue="MATH-221" due-to="Dieter Roth">
+ Changed the Complex.equals() method so that it considers +0 and -0 are equal,
+ as required by IEEE-754 standard.
+ </action>
<action dev="luc" type="add" issue="MATH-220" >
Added JAMA-like interfaces for decomposition algorithms. These interfaces
decompose a matrix as a product of several other matrices with predefined
Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java?rev=690308&r1=690307&r2=690308&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java Fri Aug 29 08:46:22 2008
@@ -690,4 +690,10 @@
public void testTanhCritical() {
TestUtils.assertSame(nanInf, new Complex(0, pi/2).tanh());
}
+
+ /** test issue MATH-221 */
+ public void testMath221() {
+ assertEquals(new Complex(0,-1), new Complex(0,1).multiply(new Complex(-1,0)));
+ }
+
}
Re: svn commit: r690308 - in /commons/proper/math/branches/MATH_2_0/src:
java/org/apache/commons/math/complex/Complex.java site/xdoc/changes.xml test/org/apache/commons/math/complex/ComplexTest.java
Posted by Luc Maisonobe <Lu...@free.fr>.
luc@apache.org a écrit :
> Author: luc
> Date: Fri Aug 29 08:46:22 2008
> New Revision: 690308
>
> URL: http://svn.apache.org/viewvc?rev=690308&view=rev
> Log:
> Changed the Complex.equals() method so that it considers +0 and -0 are equal,
> as required by IEEE-754 standard.
> JIRA: MATH-221
The fix below for issue https://issues.apache.org/jira/browse/MATH-221
is based on the following behavior:
In IEEE-754, zero is a signed value, i.e. there are both a +0 and a -0
numbers, each with its own specific representation. The IEEE-754
standard includes a rule saying these two numbers should always compare
as equal. This is directly implemented in all processors and in the JVM
when using the equality operator == on native doubles. However, we did
not use these operator on the native doubles but on the long
representation of such doubles returned by the
Double.doubleToRawLongBits() method. Since the two representations are
different (the sign bit is flipped), we considered -0 and +0 where not
the same number.
I think using Double.doubleToRawLongBits() comes from the special cases
handling for NaN, because as documented in the Complex.equals() javadoc,
we consider all NaN values to be equal (which is *not* what IEEE-754
says). I understand the rationale for NaN in this class, but once this
special case has been handled, I think relying on the native double ==
operator is better as it handles such weird cases as +/-0 better.
We did the same trick for RealMatrixImpl, and I copied this trick also
when implementing RealVectorImpl and Vector3D. I will remove it from all
three classes now.
Luc
>
> Modified:
> commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java
> commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
> commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java
>
> Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java?rev=690308&r1=690307&r2=690308&view=diff
> ==============================================================================
> --- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java (original)
> +++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/complex/Complex.java Fri Aug 29 08:46:22 2008
> @@ -255,10 +255,7 @@
> if (rhs.isNaN()) {
> ret = this.isNaN();
> } else {
> - ret = (Double.doubleToRawLongBits(real) ==
> - Double.doubleToRawLongBits(rhs.getReal())) &&
> - (Double.doubleToRawLongBits(imaginary) ==
> - Double.doubleToRawLongBits(rhs.getImaginary()));
> + ret = (real == rhs.real) && (imaginary == rhs.imaginary);
> }
> } catch (ClassCastException ex) {
> // ignore exception
>
> Modified: commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
> URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml?rev=690308&r1=690307&r2=690308&view=diff
> ==============================================================================
> --- commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml (original)
> +++ commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml Fri Aug 29 08:46:22 2008
> @@ -39,6 +39,10 @@
> </properties>
> <body>
> <release version="2.0" date="TBD" description="TBD">
> + <action dev="luc" type="fix" issue="MATH-221" due-to="Dieter Roth">
> + Changed the Complex.equals() method so that it considers +0 and -0 are equal,
> + as required by IEEE-754 standard.
> + </action>
> <action dev="luc" type="add" issue="MATH-220" >
> Added JAMA-like interfaces for decomposition algorithms. These interfaces
> decompose a matrix as a product of several other matrices with predefined
>
> Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java?rev=690308&r1=690307&r2=690308&view=diff
> ==============================================================================
> --- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java (original)
> +++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/complex/ComplexTest.java Fri Aug 29 08:46:22 2008
> @@ -690,4 +690,10 @@
> public void testTanhCritical() {
> TestUtils.assertSame(nanInf, new Complex(0, pi/2).tanh());
> }
> +
> + /** test issue MATH-221 */
> + public void testMath221() {
> + assertEquals(new Complex(0,-1), new Complex(0,1).multiply(new Complex(-1,0)));
> + }
> +
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org