[CSHARP-2098] Decimal128.Compare() gives inaccurate results Created: 17/Nov/17  Updated: 22/Jun/18  Resolved: 22/Jun/18

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dr OK [X] Assignee: John Murphy
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-2001 Decimal128.ToDecimal should not throw... Closed

 Description   

Decimal128.Compare() returns incorrect results. In the example below, the result should be 0, instead of -1.

var a = Decimal128.Parse("10");
var b = Decimal128.Parse("1E1");
var compres = Decimal128.Compare(a, b);



 Comments   
Comment by John Murphy [ 22/Jun/18 ]

Hello Dr OK,

Please note that this issue was addressed by the work done in CSHARP-2001.

Previous to this if the exponents differed the Decimal128 would not be considered equal, which is why you were getting a Compare() result of -1.

Closing this as a duplicate.

Comment by Guillermo Prandi [ 28/Dec/17 ]

In my PC (2.5.0):
var a=Decimal128.Parse("10") gives _highBits=0x0x0000000000000000, _lowBits=0x000000000000000a.
var b=Decimal128.Parse("1E1") gives _highBits=0x0x0002000000000000, _lowBits=0x0000000000000001.
a.ToString() gives "10".
b.ToString() gives "1E+1".
However, Decimal.Compare(a,b) correctly returns 0. Perhaps it's fixed?

Generated at Wed Feb 07 21:41:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.