mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-04 03:44:58 +00:00
Merge branch 'CPDecimalNumber' of http://github.com/klaaspieter/cappuccino into CPDecimalNumber
This commit is contained in:
commit
411a634242
2 files changed
+28
-15
No files matched your search
+12
-11
@@ -101,6 +101,9 @@ CPDecimal format:
|
||||
// FIXME: locale support and Cocoaify, needs to accept .1 and leading 0s
|
||||
function CPDecimalMakeWithString(string, locale)
|
||||
{
|
||||
if (!string)
|
||||
return CPDecimalMakeZero();
|
||||
|
||||
// Regexp solution as found in JSON spec, with working regexp (I added groupings)
|
||||
// Test here: http://www.regexplanet.com/simple/index.html
|
||||
// Info from: http://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly
|
||||
@@ -246,15 +249,13 @@ function CPDecimalIsZero(dcm)
|
||||
// exponent doesnt matter as long as mantissa = 0
|
||||
if (!dcm._isNaN)
|
||||
{
|
||||
for(i=0; i<[dcm._mantissa count]; i++)
|
||||
{
|
||||
if (dcm._mantissa[i] != 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < dcm._mantissa.length; i++)
|
||||
if (dcm._mantissa[i] !== 0)
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -1181,7 +1182,7 @@ function CPDecimalNormalize(dcm1, dcm2, roundingMode, longMode)
|
||||
else
|
||||
l = MIN((CPDecimalMaxDigits*factor) - l1, e); //(e1 - e2));
|
||||
|
||||
for (i = 0; i < l; i++)
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
if (e2 > e1)
|
||||
[dcm2._mantissa addObject:0]; //dcm2._mantissa[i + l2] = 0;
|
||||
@@ -1223,7 +1224,7 @@ function CPDecimalNormalize(dcm1, dcm2, roundingMode, longMode)
|
||||
{
|
||||
l1 = [dcm1._mantissa count];
|
||||
l = MIN((CPDecimalMaxDigits*factor) - l1, ABS(dcm1._exponent - dcm2._exponent));
|
||||
for (i = 0; i < l; i++)
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
dcm1._mantissa[i + l1] = 0; // or addObject: ? one faster than other?
|
||||
}
|
||||
@@ -1232,7 +1233,7 @@ function CPDecimalNormalize(dcm1, dcm2, roundingMode, longMode)
|
||||
} else {
|
||||
l2 = [dcm2._mantissa count];
|
||||
l = MIN((CPDecimalMaxDigits*factor) - l2, ABS(dcm2._exponent - dcm1._exponent));
|
||||
for (i = 0; i < l; i++)
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
dcm2._mantissa[i + l2] = 0; // or addObject: ? one faster than other?
|
||||
}
|
||||
@@ -1327,7 +1328,7 @@ function CPDecimalRound(result, dcm, scale ,roundingMode)
|
||||
|
||||
if (up)
|
||||
{
|
||||
for (i = l-1; i >= 0; i--)
|
||||
for (var i = l-1; i >= 0; i--)
|
||||
{
|
||||
if (result._mantissa[i] != 9)
|
||||
{
|
||||
|
||||
@@ -158,11 +158,18 @@ _cappdefaultDcmHandler = [CPDecimalNumberHandler decimalNumberHandlerWithRoundin
|
||||
mathematical operations to go with it.
|
||||
This class is mutable.
|
||||
*/
|
||||
@implementation CPDecimalNumber : CPObject
|
||||
|
||||
|
||||
@implementation CPDecimalNumber : CPNumber
|
||||
{
|
||||
CPDecimal _data;
|
||||
}
|
||||
|
||||
+ (id)alloc
|
||||
{
|
||||
return class_createInstance(self);
|
||||
}
|
||||
|
||||
// initializers
|
||||
- (id)init
|
||||
{
|
||||
@@ -449,10 +456,10 @@ _cappdefaultDcmHandler = [CPDecimalNumberHandler decimalNumberHandlerWithRoundin
|
||||
return @"d";
|
||||
}
|
||||
|
||||
// FIXME: I expect here locale should be some default locale
|
||||
- (CPString)stringValue
|
||||
- (CPString)description
|
||||
{
|
||||
return [self descriptionWithLocale:nil];
|
||||
// FIXME: I expect here locale should be some default locale
|
||||
return [self descriptionWithLocale:nil]
|
||||
}
|
||||
|
||||
- (CPString)descriptionWithLocale:(CPDictionary)locale
|
||||
@@ -460,6 +467,11 @@ _cappdefaultDcmHandler = [CPDecimalNumberHandler decimalNumberHandlerWithRoundin
|
||||
return CPDecimalString(_data, locale);
|
||||
}
|
||||
|
||||
- (CPString)stringValue
|
||||
{
|
||||
return [self description];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a new CPDecimal object (which effectively contains the
|
||||
internal decimal number representation).
|
||||
|
||||
Reference in new issue
Block a user