From fc746db70f3be9b09bbac1a002d49fa124a21673 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sat, 15 Jan 2011 16:12:06 +0200 Subject: [PATCH] Cocoa compatible constructors for CPDecimals --- Foundation/CPDecimal.j | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Foundation/CPDecimal.j b/Foundation/CPDecimal.j index 75a68047c..baaf5b355 100644 --- a/Foundation/CPDecimal.j +++ b/Foundation/CPDecimal.j @@ -102,7 +102,7 @@ CPDecimal format: function CPDecimalMakeWithString(string, locale) { if (!string) - return CPDecimalMakeZero(); + return CPDecimalMakeNaN(); // Regexp solution as found in JSON spec, with working regexp (I added groupings) // Test here: http://www.regexplanet.com/simple/index.html @@ -116,7 +116,7 @@ function CPDecimalMakeWithString(string, locale) // If yes simply add '?' after integer part group, ie ([+\-]?)((?:0|[1-9]\d*)?) var matches = string.match(/^([+\-]?)((?:0|[1-9]\d*))(?:\.(\d*))?(?:[eE]([+\-]?)(\d+))?$/); if (!matches) - return nil; + return CPDecimalMakeNaN(); var ds = matches[1], intpart = matches[2], @@ -143,7 +143,7 @@ function CPDecimalMakeWithString(string, locale) } if (exponent > CPDecimalMaxExponent || exponent < CPDecimalMinExponent) - return nil; + return CPDecimalMakeNaN(); // Representation internally starts at most significant digit var m = [CPArray array], @@ -190,7 +190,7 @@ function CPDecimalMakeWithParts(mantissa, exponent) [m addObject: 0]; if (exponent > CPDecimalMaxExponent || exponent < CPDecimalMinExponent) - return nil; + return CPDecimalMakeNaN(); // remaining digits are disposed of via truncation while ((mantissa > 0) && ([m count] < CPDecimalMaxDigits)) // count selector here could be optimised away @@ -256,7 +256,7 @@ function _CPDecimalMakeMinimum() i = 0; for (; i < CPDecimalMaxDigits; i++) s += "9"; - s += "e" + CPDecimalMinExponent; + s += "e" + CPDecimalMaxExponent; return CPDecimalMakeWithString(s); }