Projects  >  Math.NET Iridium (IRID)

  Issues    

 

 HyperLink  http://tracker.opensourcedotnet.info/Default.aspx?p=2&i=178 
IRID-178 - Weak Implementation Complex.GetHashCode()
Created: 02/07/2008 19:42:21    
Revised: 03/07/2008 09:10:40
   Back to Issue Filter   
      
<< >>
Simply XORing the real and the imaginary part of a complex number leads to most likely appearing hash code collisions (e.g. 1+0i and 0+1i). Thus it is desired to distinguish between the real and the imaginary part.
Proposals:
return real.GetHashCode() ^ imag.GetHashCode().GetHashCode()
or
return real.GetHashCode() ^ (imag + double.Epsilon).GetHashCode()

 
 
 
Comments (3)Attachments (0)Issue Links (0)History

Christoph Rüegg  

03/07/2008 09:10:40 * CLOSING COMMENT *

Implemented in revision 463:

return real.GetHashCode() ^ (-imag.GetHashCode());

 

 

Christoph Rüegg  

03/07/2008 08:51:33

Note, since GetHashCode of a Int32 returns itself, the first version is no option. The second version might be broken, too, since for large numbers adding epsilon might not have any effect. I'll use the Number.Increment method instead.

 

 

Christoph Rüegg  

02/07/2008 19:54:14

Confirmed, thanks for reporting. Fix scheduled for the next release.

 

 

Issue ID IRID-178
Type Enhancement Enhancement
Priority Low Low
Severity Trivial Trivial
Visibility Everyone 
Assigned To Christoph Rüegg 
Reported By * Anonymous User * 
Component Core 
Fixed For Version [2008.8.16.470] 2008 August (2008.8.16.470) 
Affected Versions  
Risk Level No Risk 
Status Closed Closed   
Resolution Complete   
Start Date ? 
Due Date ? 
Votes 0  
 Print Friendly