API  0.9.10
CPDecimalNumber.j
Go to the documentation of this file.
1 /*
2  * CPDecimalNumber.j
3  * Foundation
4  *
5  * Created by Stephen Paul Ierodiaconou
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 
23 // The default global behavior class, created lazily
25  CPDecimalNumberUIDs = new CFMutableDictionary();
26 
33 {
34  CPRoundingMode _roundingMode;
35  short _scale;
36  BOOL _raiseOnExactness;
37  BOOL _raiseOnOverflow;
38  BOOL _raiseOnUnderflow;
39  BOOL _raiseOnDivideByZero;
40 }
41 
42 // initializers
49 - (id)init
50 {
51  return [self initWithRoundingMode:CPRoundPlain
52  scale:0
54  raiseOnOverflow:YES
57 }
58 
80 - (id)initWithRoundingMode:(CPRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
81 {
82  if (self = [super init])
83  {
84  _roundingMode = roundingMode;
85  _scale = scale;
86  _raiseOnExactness = exact;
87  _raiseOnOverflow = overflow;
88  _raiseOnUnderflow = underflow;
89  _raiseOnDivideByZero = divideByZero;
90  }
91 
92  return self;
93 }
94 
95 // class methods
101 + (id)decimalNumberHandlerWithRoundingMode:(CPRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
102 {
103  return [[self alloc] initWithRoundingMode:roundingMode
104  scale:scale
105  raiseOnExactness:exact
106  raiseOnOverflow:overflow
107  raiseOnUnderflow:underflow
108  raiseOnDivideByZero:divideByZero];
109 }
110 
118 {
119  if (!CPDefaultDcmHandler)
121 
122  return CPDefaultDcmHandler;
123 }
124 
125 @end
126 
127 // CPDecimalNumberBehaviors protocol
128 
130 
131 - (CPRoundingMode)roundingMode;
132 
133 - (short)scale;
134  // The scale could return NO_SCALE for no defined scale.
135 
136 - (CPDecimalNumber)exceptionDuringOperation:(SEL)operation error:(CPCalculationError)error leftOperand:(CPDecimalNumber)leftOperand rightOperand:(CPDecimalNumber)rightOperand;
137  // Receiver can raise, return a new value, or return nil to ignore the exception.
138 
139 @end
140 
142 
148 - (CPRoundingMode)roundingMode
149 {
150  return _roundingMode;
151 }
152 
157 - (short)scale
158 {
159  return _scale;
160 }
161 
180 - (CPDecimalNumber)exceptionDuringOperation:(SEL)operation error:(CPCalculationError)error leftOperand:(CPDecimalNumber)leftOperand rightOperand:(CPDecimalNumber)rightOperand
181 {
182  switch (error)
183  {
184  case CPCalculationNoError:
185  break;
186 
188  if (_raiseOnOverflow)
189  [CPException raise:CPDecimalNumberOverflowException reason:("A CPDecimalNumber overflow has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
190  else
191  return [CPDecimalNumber notANumber];
192  break;
193 
195  if (_raiseOnUnderflow)
196  [CPException raise:CPDecimalNumberUnderflowException reason:("A CPDecimalNumber underflow has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
197  else
198  return [CPDecimalNumber notANumber];
199  break;
200 
202  if (_raiseOnExactness)
203  [CPException raise:CPDecimalNumberExactnessException reason:("A CPDecimalNumber has been rounded off during a calculation. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
204  break;
205 
207  if (_raiseOnDivideByZero)
208  [CPException raise:CPDecimalNumberDivideByZeroException reason:("A CPDecimalNumber divide by zero has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
209  else
210  return [CPDecimalNumber notANumber]; // Div by zero returns NaN
211  break;
212 
213  default:
214  [CPException raise:CPInvalidArgumentException reason:("An unknown CPDecimalNumber error has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')")];
215  }
216 
217  return nil;
218 }
219 
220 @end
221 
222 // CPCoding category
223 var CPDecimalNumberHandlerRoundingModeKey = @"CPDecimalNumberHandlerRoundingModeKey",
224  CPDecimalNumberHandlerScaleKey = @"CPDecimalNumberHandlerScaleKey",
225  CPDecimalNumberHandlerRaiseOnExactKey = @"CPDecimalNumberHandlerRaiseOnExactKey",
226  CPDecimalNumberHandlerRaiseOnOverflowKey = @"CPDecimalNumberHandlerRaiseOnOverflowKey",
227  CPDecimalNumberHandlerRaiseOnUnderflowKey = @"CPDecimalNumberHandlerRaiseOnUnderflowKey",
228  CPDecimalNumberHandlerDivideByZeroKey = @"CPDecimalNumberHandlerDivideByZeroKey";
229 
231 
236 - (id)initWithCoder:(CPCoder)aCoder
237 {
238  if (self)
239  {
240  [self initWithRoundingMode:[aCoder decodeIntForKey:CPDecimalNumberHandlerRoundingModeKey]
241  scale:[aCoder decodeIntForKey:CPDecimalNumberHandlerScaleKey]
242  raiseOnExactness:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnExactKey]
243  raiseOnOverflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnOverflowKey]
244  raiseOnUnderflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnUnderflowKey]
245  raiseOnDivideByZero:[aCoder decodeBoolForKey:CPDecimalNumberHandlerDivideByZeroKey]];
246  }
247 
248  return self;
249 }
250 
255 - (void)encodeWithCoder:(CPCoder)aCoder
256 {
257  [aCoder encodeInt:[self roundingMode] forKey:CPDecimalNumberHandlerRoundingModeKey];
258  [aCoder encodeInt:[self scale] forKey:CPDecimalNumberHandlerScaleKey];
259  [aCoder encodeBool:_raiseOnExactness forKey:CPDecimalNumberHandlerRaiseOnExactKey];
260  [aCoder encodeBool:_raiseOnOverflow forKey:CPDecimalNumberHandlerRaiseOnOverflowKey];
261  [aCoder encodeBool:_raiseOnUnderflow forKey:CPDecimalNumberHandlerRaiseOnUnderflowKey];
262  [aCoder encodeBool:_raiseOnDivideByZero forKey:CPDecimalNumberHandlerDivideByZeroKey];
263 }
264 
265 @end
266 
313 @implementation CPDecimalNumber : CPNumber
314 {
315  CPDecimal _data;
316 }
317 
324 + (id)alloc
325 {
326  // overriding alloc means CPDecimalNumbers are not toll free bridged
327  return class_createInstance(self);
328 }
329 
330 // initializers
335 - (id)init
336 {
337  return [self initWithDecimal:CPDecimalMakeNaN()];
338 }
339 
345 - (id)initWithDecimal:(CPDecimal)dcm
346 {
347  if (self = [super init])
348  _data = CPDecimalCopy(dcm);
349 
350  return self;
351 }
352 
365 - (id)initWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
366 {
367  if (self = [self init])
368  {
369  if (flag)
370  mantissa *= -1;
371 
372  _data = CPDecimalMakeWithParts(mantissa, exponent);
373  }
374 
375  return self;
376 }
377 
385 - (id)initWithString:(CPString)numberValue
386 {
387  return [self initWithString:numberValue locale:nil];
388 }
389 
399 - (id)initWithString:(CPString)numberValue locale:(CPDictionary)locale
400 {
401  if (self = [self init])
402  {
403  _data = CPDecimalMakeWithString(numberValue, locale);
404  }
405 
406  return self;
407 }
408 
409 // class methods
415 + (CPDecimalNumber)decimalNumberWithDecimal:(CPDecimal)dcm
416 {
417  return [[self alloc] initWithDecimal:dcm];
418 }
419 
428 + (CPDecimalNumber)decimalNumberWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
429 {
430  return [[self alloc] initWithMantissa:mantissa exponent:exponent isNegative:flag];
431 }
432 
440 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue
441 {
442  return [[self alloc] initWithString:numberValue];
443 }
444 
454 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue locale:(CPDictionary)locale
455 {
456  return [[self alloc] initWithString:numberValue locale:locale];
457 }
458 
463 + (id)defaultBehavior
464 {
466 }
467 
473 + (void)setDefaultBehavior:(id <CPDecimalNumberBehaviors>)behavior
474 {
475  CPDefaultDcmHandler = behavior;
476 }
477 
484 + (CPDecimalNumber)maximumDecimalNumber
485 {
486  return [[self alloc] initWithDecimal:_CPDecimalMakeMaximum()];
487 }
488 
495 + (CPDecimalNumber)minimumDecimalNumber
496 {
497  return [[self alloc] initWithDecimal:_CPDecimalMakeMinimum()];
498 }
499 
504 + (CPDecimalNumber)notANumber
505 {
506  return [[self alloc] initWithDecimal:CPDecimalMakeNaN()];
507 }
508 
514 {
515  return [[self alloc] initWithDecimal:CPDecimalMakeZero()];
516 }
517 
523 {
524  return [[self alloc] initWithDecimal:CPDecimalMakeOne()];
525 }
526 
527 // instance methods
528 
530 {
531  var UID = CPDecimalNumberUIDs.valueForKey(self);
532 
533  if (!UID)
534  {
535  UID = objj_generateObjectUID();
536  CPDecimalNumberUIDs.setValueForKey(self, UID);
537  }
538 
539  return UID + "";
540 }
541 
549 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber
550 {
552 }
553 
562 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
563 {
564  var result = CPDecimalMakeZero(),
565  error = CPDecimalAdd(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
566 
567  if (error > CPCalculationNoError)
568  {
569  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
570  if (res != nil)
571  return res;
572  }
573 
575 }
576 
585 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber
586 {
588 }
589 
599 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
600 {
601  var result = CPDecimalMakeZero(),
602  error = CPDecimalSubtract(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
603 
604  if (error > CPCalculationNoError)
605  {
606  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
607 
608  if (res != nil)
609  return res;
610  }
611 
613 }
614 
623 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber
624 {
626 }
627 
637 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
638 {
639  var result = CPDecimalMakeZero(),
640  error = CPDecimalDivide(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
641 
642  if (error > CPCalculationNoError)
643  {
644  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
645  if (res != nil)
646  return res;
647  }
648 
650 }
651 
660 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber
661 {
663 }
664 
674 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
675 {
676  var result = CPDecimalMakeZero(),
677  error = CPDecimalMultiply(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
678 
679  if (error > CPCalculationNoError)
680  {
681  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
682 
683  if (res != nil)
684  return res;
685  }
686 
688 }
689 
698 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power
699 {
701 }
702 
712 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
713 {
714  var result = CPDecimalMakeZero(),
715  error = CPDecimalMultiplyByPowerOf10(result, [self decimalValue], power, [behavior roundingMode]);
716 
717  if (error > CPCalculationNoError)
718  {
719  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
720 
721  if (res != nil)
722  return res;
723  }
724 
726 }
727 
736 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power
737 {
739 }
740 
750 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
751 {
752  if (power < 0)
753  return [behavior exceptionDuringOperation:_cmd error:-1 leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
754 
755  var result = CPDecimalMakeZero(),
756  error = CPDecimalPower(result, [self decimalValue], power, [behavior roundingMode]);
757 
758  if (error > CPCalculationNoError)
759  {
760  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
761 
762  if (res != nil)
763  return res;
764  }
765 
767 }
768 
776 - (CPDecimalNumber)decimalNumberByRoundingAccordingToBehavior:(id <CPDecimalNumberBehaviors>)behavior
777 {
778  var result = CPDecimalMakeZero();
779 
780  CPDecimalRound(result, [self decimalValue], [behavior scale], [behavior roundingMode]);
781 
783 }
784 
792 - (CPComparisonResult)compare:(CPNumber)aNumber
793 {
794  // aNumber type is checked to convert if appropriate
795  if (![aNumber isKindOfClass:[CPDecimalNumber class]])
796  aNumber = [CPDecimalNumber decimalNumberWithString:aNumber.toString()];
797 
798  return CPDecimalCompare([self decimalValue], [aNumber decimalValue]);
799 }
800 
805 - (CPString)objCType
806 {
807  return @"d";
808 }
809 
815 {
816  return [self descriptionWithLocale:nil]
817 }
818 
825 - (CPString)descriptionWithLocale:(CPDictionary)locale
826 {
827  return CPDecimalString(_data, locale);
828 }
829 
834 - (CPString)stringValue
835 {
836  return [self description];
837 }
838 
844 - (CPDecimal)decimalValue
845 {
846  return CPDecimalCopy(_data);
847 }
848 
849 // Type Conversion Methods
854 - (double)doubleValue
855 {
856  // FIXME: locale support / bounds check?
857  return parseFloat([self stringValue]);
858 }
859 
864 - (BOOL)boolValue
865 {
866  return (CPDecimalIsZero(_data))?NO:YES;
867 }
868 
873 - (char)charValue
874 {
875  // FIXME: locale support / bounds check?
876  return parseInt([self stringValue]);
877 }
878 
883 - (float)floatValue
884 {
885  // FIXME: locale support / bounds check?
886  return parseFloat([self stringValue]);
887 }
888 
893 - (int)intValue
894 {
895  // FIXME: locale support / bounds check?
896  return parseInt([self stringValue]);
897 }
898 
903 - (long long)longLongValue
904 {
905  // FIXME: locale support / bounds check?
906  return parseInt([self stringValue]);
907 }
908 
913 - (long)longValue
914 {
915  // FIXME: locale support / bounds check?
916  return parseInt([self stringValue]);
917 }
918 
923 - (short)shortValue
924 {
925  // FIXME: locale support / bounds check?
926  return parseInt([self stringValue]);
927 }
928 
933 - (unsigned char)unsignedCharValue
934 {
935  // FIXME: locale support / bounds check?
936  return parseInt([self stringValue]);
937 }
938 
943 - (unsigned int)unsignedIntValue
944 {
945  // FIXME: locale support / bounds check?
946  return parseInt([self stringValue]);
947 }
948 
953 - (unsigned long)unsignedLongValue
954 {
955  // FIXME: locale support / bounds check?
956  return parseInt([self stringValue]);
957 }
958 
963 - (unsigned short)unsignedShortValue
964 {
965  // FIXME: locale support / bounds check?
966  return parseInt([self stringValue]);
967 }
968 
969 // CPNumber inherited methods
976 - (BOOL)isEqualToNumber:(CPNumber)aNumber
977 {
978  return (CPDecimalCompare(CPDecimalMakeWithString(aNumber.toString(),nil), _data) == CPOrderedSame)?YES:NO;
979 }
980 
986 + (id)numberWithBool:(BOOL)aBoolean
987 {
988  return [[self alloc] initWithBool:aBoolean];
989 }
990 
996 + (id)numberWithChar:(char)aChar
997 {
998  return [[self alloc] initWithChar:aChar];
999 }
1000 
1006 + (id)numberWithDouble:(double)aDouble
1007 {
1008  return [[self alloc] initWithDouble:aDouble];
1009 }
1010 
1016 + (id)numberWithFloat:(float)aFloat
1017 {
1018  return [[self alloc] initWithFloat:aFloat];
1019 }
1020 
1026 + (id)numberWithInt:(int)anInt
1027 {
1028  return [[self alloc] initWithInt:anInt];
1029 }
1030 
1036 + (id)numberWithLong:(long)aLong
1037 {
1038  return [[self alloc] initWithLong:aLong];
1039 }
1040 
1046 + (id)numberWithLongLong:(long long)aLongLong
1047 {
1048  return [[self alloc] initWithLongLong:aLongLong];
1049 }
1050 
1056 + (id)numberWithShort:(short)aShort
1057 {
1058  return [[self alloc] initWithShort:aShort];
1059 }
1060 
1066 + (id)numberWithUnsignedChar:(unsigned char)aChar
1067 {
1068  return [[self alloc] initWithUnsignedChar:aChar];
1069 }
1070 
1076 + (id)numberWithUnsignedInt:(unsigned)anUnsignedInt
1077 {
1078  return [[self alloc] initWithUnsignedInt:anUnsignedInt];
1079 }
1080 
1086 + (id)numberWithUnsignedLong:(unsigned long)anUnsignedLong
1087 {
1088  return [[self alloc] initWithUnsignedLong:anUnsignedLong];
1089 }
1090 
1096 + (id)numberWithUnsignedLongLong:(unsigned long)anUnsignedLongLong
1097 {
1098  return [[self alloc] initWithUnsignedLongLong:anUnsignedLongLong];
1099 }
1100 
1106 + (id)numberWithUnsignedShort:(unsigned short)anUnsignedShort
1107 {
1108  return [[self alloc] initWithUnsignedShort:anUnsignedShort];
1109 }
1110 
1116 - (id)initWithBool:(BOOL)value
1117 {
1118  if (self = [self init])
1119  _data = CPDecimalMakeWithParts((value)?1:0, 0);
1120  return self;
1121 }
1122 
1128 - (id)initWithChar:(char)value
1129 {
1130  return [self _initWithJSNumber:value];
1131 }
1132 
1138 - (id)initWithDouble:(double)value
1139 {
1140  return [self _initWithJSNumber:value];
1141 }
1142 
1148 - (id)initWithFloat:(float)value
1149 {
1150  return [self _initWithJSNumber:value];
1151 }
1152 
1158 - (id)initWithInt:(int)value
1159 {
1160  return [self _initWithJSNumber:value];
1161 }
1162 
1168 - (id)initWithLong:(long)value
1169 {
1170  return [self _initWithJSNumber:value];
1171 }
1172 
1178 - (id)initWithLongLong:(long long)value
1179 {
1180  return [self _initWithJSNumber:value];
1181 }
1182 
1188 - (id)initWithShort:(short)value
1189 {
1190  return [self _initWithJSNumber:value];
1191 }
1192 
1198 - (id)initWithUnsignedChar:(unsigned char)value
1199 {
1200  return [self _initWithJSNumber:value];
1201 }
1202 
1208 - (id)initWithUnsignedInt:(unsigned)value
1209 {
1210  return [self _initWithJSNumber:value];
1211 }
1212 
1218 - (id)initWithUnsignedLong:(unsigned long)value
1219 {
1220  return [self _initWithJSNumber:value];
1221 }
1222 
1228 - (id)initWithUnsignedLongLong:(unsigned long long)value
1229 {
1230  return [self _initWithJSNumber:value];
1231 }
1232 
1238 - (id)initWithUnsignedShort:(unsigned short)value
1239 {
1240  return [self _initWithJSNumber:value];
1241 }
1242 
1243 - (id)_initWithJSNumber:value
1244 {
1245  if (self = [self init])
1246  _data = CPDecimalMakeWithString(value.toString(), nil);
1247  return self;
1248 }
1249 
1250 @end
1251 
1252 // CPCoding category
1253 var CPDecimalNumberDecimalExponent = @"CPDecimalNumberDecimalExponent",
1254  CPDecimalNumberDecimalIsNegative = @"CPDecimalNumberDecimalIsNegative",
1255  CPDecimalNumberDecimalIsCompact = @"CPDecimalNumberDecimalIsCompact",
1256  CPDecimalNumberDecimalIsNaN = @"CPDecimalNumberDecimalIsNaN",
1257  CPDecimalNumberDecimalMantissa = @"CPDecimalNumberDecimalMantissa";
1258 
1260 
1265 - (id)initWithCoder:(CPCoder)aCoder
1266 {
1267  if (self)
1268  {
1269  var dcm = CPDecimalMakeZero();
1270  dcm._exponent = [aCoder decodeIntForKey:CPDecimalNumberDecimalExponent];
1271  dcm._isNegative = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNegative];
1272  dcm._isCompact = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsCompact];
1273  dcm._isNaN = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNaN];
1274  dcm._mantissa = [aCoder decodeObjectForKey:CPDecimalNumberDecimalMantissa];
1275  [self initWithDecimal:dcm];
1276  }
1277 
1278  return self;
1279 }
1280 
1285 - (void)encodeWithCoder:(CPCoder)aCoder
1286 {
1287  [aCoder encodeInt:_data._exponent forKey:CPDecimalNumberDecimalExponent];
1288  [aCoder encodeBool:_data._isNegative forKey:CPDecimalNumberDecimalIsNegative];
1289  [aCoder encodeBool:_data._isCompact forKey:CPDecimalNumberDecimalIsCompact];
1290  [aCoder encodeBool:_data._isNaN forKey:CPDecimalNumberDecimalIsNaN];
1291  [aCoder encodeObject:_data._mantissa forKey:CPDecimalNumberDecimalMantissa];
1292 }
1293 
1294 @end
function CPDecimalMakeZero()
Definition: CPDecimal.j:229
CPCalculationUnderflow
Definition: CPDecimal.j:67
Used to implement exception handling (creating & raising).
Definition: CPException.h:2
function CPDecimalRound(result, dcm, scale, roundingMode)
Definition: CPDecimal.j:1341
var CPDecimalNumberDecimalMantissa
var CPDecimalNumberDecimalExponent
function CPDecimalMultiply(result, leftOperand, rightOperand, roundingMode, powerMode)
Definition: CPDecimal.j:1032
function CPDecimalMakeWithString(string, locale)
Definition: CPDecimal.j:104
var CPDecimalNumberDecimalIsNaN
var CPDecimalNumberHandlerRaiseOnUnderflowKey
CPOrderedSame
Definition: CPObjJRuntime.j:54
CPDecimalNumber decimalNumberBySubtracting:withBehavior:(CPDecimalNumber decimalNumber, [withBehavior] id< CPDecimalNumberBehaviors > behavior)
function CPDecimalSubtract(result, leftOperand, rightOperand, roundingMode)
Definition: CPDecimal.j:688
var CPDecimalNumberUIDs
CPDecimalNumber decimalNumberWithDecimal:(CPDecimal dcm)
CPString descriptionWithLocale:(CPDictionary locale)
function CPDecimalIsZero(dcm)
Definition: CPDecimal.j:283
CPDecimalNumber decimalNumberWithString:(CPString numberValue)
CPDecimalNumber decimalNumberByDividingBy:withBehavior:(CPDecimalNumber decimalNumber, [withBehavior] id< CPDecimalNumberBehaviors > behavior)
void raise:reason:(CPString aName, [reason] CPString aReason)
Definition: CPException.j:66
id initWithUnsignedLongLong:(unsigned long long value)
function CPDecimalCopy(dcm)
Definition: CPDecimal.j:361
id initWithString:locale:(CPString numberValue, [locale] CPDictionary locale)
var CPDecimalNumberHandlerRaiseOnOverflowKey
function CPDecimalString(dcm, locale)
Definition: CPDecimal.j:1504
function CPDecimalMultiplyByPowerOf10(result, dcm, power, roundingMode)
Definition: CPDecimal.j:1131
CPString description()
Definition: CPObject.j:358
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPCalculationDivideByZero
Definition: CPDecimal.j:68
id initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:(CPRoundingMode roundingMode, [scale] short scale, [raiseOnExactness] BOOL exact, [raiseOnOverflow] BOOL overflow, [raiseOnUnderflow] BOOL underflow, [raiseOnDivideByZero] BOOL divideByZero)
CPString description()
An immutable string (collection of characters).
Definition: CPString.h:2
var CPDecimalNumberHandlerRaiseOnExactKey
var CPDecimalNumberDecimalIsNegative
Decimal floating point number.
Decimal floating point number exception and rounding behavior. This class is mutable.
CPCalculationLossOfPrecision
Definition: CPDecimal.j:65
function CPDecimalPower(result, dcm, power, roundingMode)
Definition: CPDecimal.j:1162
CPDecimalNumber decimalNumberByMultiplyingBy:withBehavior:(CPDecimalNumber decimalNumber, [withBehavior] id< CPDecimalNumberBehaviors > behavior)
var CPDecimalNumberHandlerRoundingModeKey
function CPDecimalAdd(result, leftOperand, rightOperand, roundingMode, longMode)
Definition: CPDecimal.j:534
function CPDecimalCompare(leftOperand, rightOperand)
Definition: CPDecimal.j:379
CPDecimalNumber decimalNumberByRaisingToPower:withBehavior:(unsigned power, [withBehavior] id< CPDecimalNumberBehaviors > behavior)
CPRoundingMode roundingMode()
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
CPDecimalNumber notANumber()
id initWithMantissa:exponent:isNegative:(unsigned long long mantissa, [exponent] short exponent, [isNegative] BOOL flag)
CPDecimalNumber decimalNumberByMultiplyingByPowerOf10:withBehavior:(short power, [withBehavior] id< CPDecimalNumberBehaviors > behavior)
id initWithDecimal:(CPDecimal dcm)
CPCalculationOverflow
Definition: CPDecimal.j:66
function CPDecimalMakeWithParts(mantissa, exponent)
Definition: CPDecimal.j:193
function CPDecimalDivide(result, leftOperand, rightOperand, roundingMode)
Definition: CPDecimal.j:888
var CPDecimalNumberHandlerScaleKey
A bridged object to native Javascript numbers.
Definition: CPNumber.h:2
var CPDecimalNumberDecimalIsCompact
var CPDecimalNumberHandlerDivideByZeroKey
CPDecimalNumber exceptionDuringOperation:error:leftOperand:rightOperand:(SEL operation, [error] CPCalculationError error, [leftOperand] CPDecimalNumber leftOperand, [rightOperand] CPDecimalNumber rightOperand)
var CPDefaultDcmHandler
CPString UID()
Definition: CPObject.j:552
id alloc()
Definition: CPObject.j:130
CPDecimalNumber decimalNumberByAdding:withBehavior:(CPDecimalNumber decimalNumber, [withBehavior] id< CPDecimalNumberBehaviors > behavior)