From 70e56ecfea98058fe1e0e9bc14c4838a4796c224 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 6 Dec 2023 17:40:06 +0000 Subject: [PATCH] bugfix by by danieljboyd@icloud.com --- ChangeLog | 5 +++++ Source/NSDecimal.m | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index f148096179..0f0f14d40f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-12-06 Daniel Boyd + + * Source/NSDecimal.m: + For compare, handle the case where one or both operands are zero. + 2023-12-05 Richard Frith-Macdonald * Source/NSMessagePort.m: diff --git a/Source/NSDecimal.m b/Source/NSDecimal.m index b40fc9f33d..c1a4983cc5 100644 --- a/Source/NSDecimal.m +++ b/Source/NSDecimal.m @@ -188,6 +188,20 @@ but small numbers can only be represented with limited exactness (one digit return NSOrderedAscending; } + // Handle zero length operands + if (leftOperand->length == 0 || rightOperand->length == 0) + { + if (leftOperand->length == 0 && rightOperand->length == 0) + return NSOrderedSame; + else if (leftOperand->length == 0) + return rightOperand->isNegative + ? NSOrderedDescending : NSOrderedAscending; + else + return leftOperand->isNegative + ? NSOrderedAscending : NSOrderedDescending; + } + + // Same sign, check size if (s1 < s2) {