[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 10:27:05 EDT 2011



Jonathan Pryor <jonpryor at vt.edu> changed:

           What    |Removed                     |Added
                 CC|                            |jonpryor at vt.edu

--- Comment #1 from Jonathan Pryor <jonpryor at vt.edu> 2011-08-04 14:27:05 UTC ---
The problem is easily summarized in `csharp`:

    csharp> 0.5m.GetHashCode();     
    csharp> 0.500m.GetHashCode();

With a quick sample app, the IL for the two differs:

    // var a = 0.5m;
        IL_0000:  ldc.i4.5 
        IL_0001:  ldc.i4.0 
        IL_0002:  ldc.i4.0 
        IL_0003:  ldc.i4.0 
        IL_0004:  ldc.i4.1 
        IL_0005:  newobj instance void valuetype
[mscorlib]System.Decimal::'.ctor'(int32, int32, int32, bool, unsigned int8)

    // var b = 0.500m;
        IL_0017:  ldc.i4 500
        IL_001c:  ldc.i4.0 
        IL_001d:  ldc.i4.0 
        IL_001e:  ldc.i4.0 
        IL_001f:  ldc.i4.3 
        IL_0020:  newobj instance void valuetype
[mscorlib]System.Decimal::'.ctor'(int32, int32, int32, bool, unsigned int8)

The underlying problem appears to be Decimal.GetHashCode():

        public override int GetHashCode () 
            return (int) (flags ^ hi ^ lo ^ mid);

Since different `hi`, `lo`, and `mid` values will be present in 0.5m and
0.500m, they have different hash code values. Meanwhile, they _do_ equal each
other (e.g. `0.5m.Equals(0.500m)==true`).

Thus, this looks to be a bug in Decimal.GetHashCode().

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