[Mono-bugs] [Bug 710262] Dictionary<decimal, > works differently on Mono and .NET

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Aug 4 14:43:57 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=710262

https://bugzilla.novell.com/show_bug.cgi?id=710262#c2


Kornél Pál <kornelpal at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kornelpal at gmail.com

--- Comment #2 from Kornél Pál <kornelpal at gmail.com> 2011-08-04 18:43:56 UTC ---
Using Double.GetHashCode seems to be an easy and straightforward solution.

I was doing some testing using MS.NET 4.0 and found out that they actually do
the same.

Console.WriteLine(Decimal.Equals(0.5m, 0.500m));               // True
Console.WriteLine(0.5m.GetHashCode() == 0.500m.GetHashCode()); // True
Console.WriteLine(0.500m.GetHashCode() == 0.5d.GetHashCode()); // True

The testing also uncovered the bug that +0 and -0 have diffent hash codes on
Mono while they should have the same because they are equal:

Console.WriteLine(Double.Equals(0d, -0d));                     // True
Console.WriteLine(0d.GetHashCode() == (-0d).GetHashCode());    // True
Console.WriteLine(Single.Equals(0f, -0f));                     // True
Console.WriteLine(0f.GetHashCode() == (-0f).GetHashCode());    // True

The same is true for Decimal (works with Mono):

Console.WriteLine(Decimal.Equals(0m, -0m));                    // True
Console.WriteLine(0m.GetHashCode() == (-0m).GetHashCode());    // True

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list