mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Fix for comparing decimal numbers < 1.0 with 0.0
This commit is contained in:
@@ -374,18 +374,21 @@ function CPDecimalCompare(leftOperand, rightOperand)
|
||||
return CPOrderedAscending;
|
||||
}
|
||||
|
||||
var s1 = leftOperand._exponent + leftOperand._mantissa.length,
|
||||
// Before comparing number size check if zero (dont use CPDecimalIsZero as it is more computationally intensive)
|
||||
var leftIsZero = (leftOperand._mantissa.length == 1 && leftOperand._mantissa[0] == 0),
|
||||
rightIsZero = (rightOperand._mantissa.length == 1 && rightOperand._mantissa[0] == 0),
|
||||
// Sign is the same, quick check size (length + exp)
|
||||
s1 = leftOperand._exponent + leftOperand._mantissa.length,
|
||||
s2 = rightOperand._exponent + rightOperand._mantissa.length;
|
||||
|
||||
// Sign is the same, quick check size (length + exp)
|
||||
if (s1 < s2)
|
||||
if (leftIsZero || s1 < s2)
|
||||
{
|
||||
if (rightOperand._isNegative)
|
||||
return CPOrderedDescending;
|
||||
else
|
||||
return CPOrderedAscending;
|
||||
}
|
||||
if (s1 > s2)
|
||||
if (rightIsZero || s1 > s2)
|
||||
{
|
||||
if (rightOperand._isNegative)
|
||||
return CPOrderedAscending;
|
||||
|
||||
@@ -339,6 +339,16 @@
|
||||
dcm = CPDecimalMakeWithString(@"-1e100");
|
||||
c = CPDecimalCompare(dcm1,dcm);
|
||||
[self assert:CPOrderedDescending equals:c message:"CPDecimalCompare() Tc4: should be descending"];
|
||||
|
||||
dcm1 = CPDecimalMakeWithString(@"0.0");
|
||||
dcm = CPDecimalMakeWithString(@"0.5");
|
||||
c = CPDecimalCompare(dcm1,dcm);
|
||||
[self assert:CPOrderedAscending equals:c message:"CPDecimalCompare() Tc4: should be descending"];
|
||||
|
||||
dcm1 = CPDecimalMakeWithString(@"0.0");
|
||||
dcm = CPDecimalMakeWithString(@"-0.5");
|
||||
c = CPDecimalCompare(dcm1,dcm);
|
||||
[self assert:CPOrderedDescending equals:c message:"CPDecimalCompare() Tc4: should be descending"];
|
||||
}
|
||||
|
||||
- (void)testCompact
|
||||
|
||||
Reference in New Issue
Block a user