Details
Description
Two complex numbers with real/imaginary parts 0.0d but different signs compare as equal numbers. This is according to their mathematical value; the comparison is done via
return (real == c.real) && (imaginary == c.imaginary);
Unfortunately, two Double values do NOT compare as equal in that case, so real.equals(c.real) would return false if the signs differ.
This becomes a problem because for the hashCode, MathUtils.hash is used on the real and imaginary parts, which in turn uses Double.hash.
This violates the contract on equals/hashCode, so Complex numbers cannot be used in a hashtable or similar data structure:
Complex c1 = new Complex(0.0, 0.0);
Complex c2 = new Complex(0.0, 0.0);
// Checks the contract: equalshashcode on c1 and c2
assertTrue("Contract failed: equalshashcode on c1 and c2", c1.equals(c2) ? c1.hashCode() == c2.hashCode() : true);
Activity
Transition  Time In Source Status  Execution Times  Last Executer  Last Execution Date  


4d 9h 56m  1  Gilles  18/Apr/14 17:00  

30d 23h 12m  1  Luc Maisonobe  19/May/14 16:13  

352d 15h 21m  1  Cyrille Artho  07/May/15 07:35  

8h 12m  1  Luc Maisonobe  07/May/15 15:47 
Status  Reopened [ 4 ]  Resolved [ 5 ] 
Fix Version/s  4.0 [ 12317577 ]  
Fix Version/s  3.6 [ 12332157 ]  
Fix Version/s  3.3 [ 12324600 ]  
Resolution  Fixed [ 1 ] 
Resolution  Fixed [ 1 ]  
Status  Closed [ 6 ]  Reopened [ 4 ] 
Status  Resolved [ 5 ]  Closed [ 6 ] 
Status  Open [ 1 ]  Resolved [ 5 ] 
Fix Version/s  3.3 [ 12324600 ]  
Resolution  Fixed [ 1 ] 
Attachment  MATH1118.patch [ 12640615 ] 
Attachment  MATH1118.patch [ 12640066 ] 
Attachment  Report5a.java [ 12640036 ] 
Field  Original Value  New Value 

Attachment  Report5.java [ 12640028 ] 
Fixed in git repository on both the master branch and the 3.X branch.
Thanks for the reminding.