API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
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 
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 
117 + (id)defaultDecimalNumberHandler
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 
314 @implementation CPDecimalNumber : CPNumber
315 {
316  CPDecimal _data;
317 }
318 
325 + (id)alloc
326 {
327  // overriding alloc means CPDecimalNumbers are not toll free bridged
328  return class_createInstance(self);
329 }
330 
331 // initializers
336 - (id)init
337 {
338  return [self initWithDecimal:CPDecimalMakeNaN()];
339 }
340 
346 - (id)initWithDecimal:(CPDecimal)dcm
347 {
348  if (self = [super init])
349  _data = CPDecimalCopy(dcm);
350 
351  return self;
352 }
353 
366 - (id)initWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
367 {
368  if (self = [self init])
369  {
370  if (flag)
371  mantissa *= -1;
372 
373  _data = CPDecimalMakeWithParts(mantissa, exponent);
374  }
375 
376  return self;
377 }
378 
386 - (id)initWithString:(CPString)numberValue
387 {
388  return [self initWithString:numberValue locale:nil];
389 }
390 
400 - (id)initWithString:(CPString)numberValue locale:(CPDictionary)locale
401 {
402  if (self = [self init])
403  {
404  _data = CPDecimalMakeWithString(numberValue, locale);
405  }
406 
407  return self;
408 }
409 
410 // class methods
416 + (CPDecimalNumber)decimalNumberWithDecimal:(CPDecimal)dcm
417 {
418  return [[self alloc] initWithDecimal:dcm];
419 }
420 
429 + (CPDecimalNumber)decimalNumberWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
430 {
431  return [[self alloc] initWithMantissa:mantissa exponent:exponent isNegative:flag];
432 }
433 
441 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue
442 {
443  return [[self alloc] initWithString:numberValue];
444 }
445 
455 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue locale:(CPDictionary)locale
456 {
457  return [[self alloc] initWithString:numberValue locale:locale];
458 }
459 
464 + (id)defaultBehavior
465 {
467 }
468 
474 + (void)setDefaultBehavior:(id <CPDecimalNumberBehaviors>)behavior
475 {
476  CPDefaultDcmHandler = behavior;
477 }
478 
485 + (CPDecimalNumber)maximumDecimalNumber
486 {
487  return [[self alloc] initWithDecimal:_CPDecimalMakeMaximum()];
488 }
489 
496 + (CPDecimalNumber)minimumDecimalNumber
497 {
498  return [[self alloc] initWithDecimal:_CPDecimalMakeMinimum()];
499 }
500 
505 + (CPDecimalNumber)notANumber
506 {
507  return [[self alloc] initWithDecimal:CPDecimalMakeNaN()];
508 }
509 
515 {
516  return [[self alloc] initWithDecimal:CPDecimalMakeZero()];
517 }
518 
524 {
525  return [[self alloc] initWithDecimal:CPDecimalMakeOne()];
526 }
527 
528 // instance methods
536 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber
537 {
539 }
540 
549 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
550 {
551  var result = CPDecimalMakeZero(),
552  error = CPDecimalAdd(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
553 
554  if (error > CPCalculationNoError)
555  {
556  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
557  if (res != nil)
558  return res;
559  }
560 
562 }
563 
572 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber
573 {
575 }
576 
586 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
587 {
588  var result = CPDecimalMakeZero(),
589  error = CPDecimalSubtract(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
590 
591  if (error > CPCalculationNoError)
592  {
593  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
594 
595  if (res != nil)
596  return res;
597  }
598 
600 }
601 
610 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber
611 {
613 }
614 
624 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
625 {
626  var result = CPDecimalMakeZero(),
627  error = CPDecimalDivide(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
628 
629  if (error > CPCalculationNoError)
630  {
631  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
632  if (res != nil)
633  return res;
634  }
635 
637 }
638 
647 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber
648 {
650 }
651 
661 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
662 {
663  var result = CPDecimalMakeZero(),
664  error = CPDecimalMultiply(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
665 
666  if (error > CPCalculationNoError)
667  {
668  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
669 
670  if (res != nil)
671  return res;
672  }
673 
675 }
676 
685 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power
686 {
688 }
689 
699 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
700 {
701  var result = CPDecimalMakeZero(),
702  error = CPDecimalMultiplyByPowerOf10(result, [self decimalValue], power, [behavior roundingMode]);
703 
704  if (error > CPCalculationNoError)
705  {
706  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
707 
708  if (res != nil)
709  return res;
710  }
711 
713 }
714 
723 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power
724 {
726 }
727 
737 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
738 {
739  if (power < 0)
740  return [behavior exceptionDuringOperation:_cmd error:-1 leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
741 
742  var result = CPDecimalMakeZero(),
743  error = CPDecimalPower(result, [self decimalValue], power, [behavior roundingMode]);
744 
745  if (error > CPCalculationNoError)
746  {
747  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
748 
749  if (res != nil)
750  return res;
751  }
752 
754 }
755 
763 - (CPDecimalNumber)decimalNumberByRoundingAccordingToBehavior:(id <CPDecimalNumberBehaviors>)behavior
764 {
765  var result = CPDecimalMakeZero();
766 
767  CPDecimalRound(result, [self decimalValue], [behavior scale], [behavior roundingMode]);
768 
770 }
771 
779 - (CPComparisonResult)compare:(CPNumber)aNumber
780 {
781  // aNumber type is checked to convert if appropriate
782  if (![aNumber isKindOfClass:[CPDecimalNumber class]])
783  aNumber = [CPDecimalNumber decimalNumberWithString:aNumber.toString()];
784 
785  return CPDecimalCompare([self decimalValue], [aNumber decimalValue]);
786 }
787 
792 - (CPString)objCType
793 {
794  return @"d";
795 }
796 
801 - (CPString)description
802 {
803  return [self descriptionWithLocale:nil]
804 }
805 
812 - (CPString)descriptionWithLocale:(CPDictionary)locale
813 {
814  return CPDecimalString(_data, locale);
815 }
816 
821 - (CPString)stringValue
822 {
823  return [self description];
824 }
825 
831 - (CPDecimal)decimalValue
832 {
833  return CPDecimalCopy(_data);
834 }
835 
836 // Type Conversion Methods
841 - (double)doubleValue
842 {
843  // FIXME: locale support / bounds check?
844  return parseFloat([self stringValue]);
845 }
846 
851 - (BOOL)boolValue
852 {
853  return (CPDecimalIsZero(_data))?NO:YES;
854 }
855 
860 - (char)charValue
861 {
862  // FIXME: locale support / bounds check?
863  return parseInt([self stringValue]);
864 }
865 
870 - (float)floatValue
871 {
872  // FIXME: locale support / bounds check?
873  return parseFloat([self stringValue]);
874 }
875 
880 - (int)intValue
881 {
882  // FIXME: locale support / bounds check?
883  return parseInt([self stringValue]);
884 }
885 
890 - (long long)longLongValue
891 {
892  // FIXME: locale support / bounds check?
893  return parseInt([self stringValue]);
894 }
895 
900 - (long)longValue
901 {
902  // FIXME: locale support / bounds check?
903  return parseInt([self stringValue]);
904 }
905 
910 - (short)shortValue
911 {
912  // FIXME: locale support / bounds check?
913  return parseInt([self stringValue]);
914 }
915 
920 - (unsigned char)unsignedCharValue
921 {
922  // FIXME: locale support / bounds check?
923  return parseInt([self stringValue]);
924 }
925 
930 - (unsigned int)unsignedIntValue
931 {
932  // FIXME: locale support / bounds check?
933  return parseInt([self stringValue]);
934 }
935 
940 - (unsigned long)unsignedLongValue
941 {
942  // FIXME: locale support / bounds check?
943  return parseInt([self stringValue]);
944 }
945 
950 - (unsigned short)unsignedShortValue
951 {
952  // FIXME: locale support / bounds check?
953  return parseInt([self stringValue]);
954 }
955 
956 // CPNumber inherited methods
963 - (BOOL)isEqualToNumber:(CPNumber)aNumber
964 {
965  return (CPDecimalCompare(CPDecimalMakeWithString(aNumber.toString(),nil), _data) == CPOrderedSame)?YES:NO;
966 }
967 
973 + (id)numberWithBool:(BOOL)aBoolean
974 {
975  return [[self alloc] initWithBool:aBoolean];
976 }
977 
983 + (id)numberWithChar:(char)aChar
984 {
985  return [[self alloc] initWithChar:aChar];
986 }
987 
993 + (id)numberWithDouble:(double)aDouble
994 {
995  return [[self alloc] initWithDouble:aDouble];
996 }
997 
1003 + (id)numberWithFloat:(float)aFloat
1004 {
1005  return [[self alloc] initWithFloat:aFloat];
1006 }
1007 
1013 + (id)numberWithInt:(int)anInt
1014 {
1015  return [[self alloc] initWithInt:anInt];
1016 }
1017 
1023 + (id)numberWithLong:(long)aLong
1024 {
1025  return [[self alloc] initWithLong:aLong];
1026 }
1027 
1033 + (id)numberWithLongLong:(long long)aLongLong
1034 {
1035  return [[self alloc] initWithLongLong:aLongLong];
1036 }
1037 
1043 + (id)numberWithShort:(short)aShort
1044 {
1045  return [[self alloc] initWithShort:aShort];
1046 }
1047 
1053 + (id)numberWithUnsignedChar:(unsigned char)aChar
1054 {
1055  return [[self alloc] initWithUnsignedChar:aChar];
1056 }
1057 
1063 + (id)numberWithUnsignedInt:(unsigned)anUnsignedInt
1064 {
1065  return [[self alloc] initWithUnsignedInt:anUnsignedInt];
1066 }
1067 
1073 + (id)numberWithUnsignedLong:(unsigned long)anUnsignedLong
1074 {
1075  return [[self alloc] initWithUnsignedLong:anUnsignedLong];
1076 }
1077 
1083 + (id)numberWithUnsignedLongLong:(unsigned long)anUnsignedLongLong
1084 {
1085  return [[self alloc] initWithUnsignedLongLong:anUnsignedLongLong];
1086 }
1087 
1093 + (id)numberWithUnsignedShort:(unsigned short)anUnsignedShort
1094 {
1095  return [[self alloc] initWithUnsignedShort:anUnsignedShort];
1096 }
1097 
1103 - (id)initWithBool:(BOOL)value
1104 {
1105  if (self = [self init])
1106  _data = CPDecimalMakeWithParts((value)?1:0, 0);
1107  return self;
1108 }
1109 
1115 - (id)initWithChar:(char)value
1116 {
1117  return [self _initWithJSNumber:value];
1118 }
1119 
1125 - (id)initWithDouble:(double)value
1126 {
1127  return [self _initWithJSNumber:value];
1128 }
1129 
1135 - (id)initWithFloat:(float)value
1136 {
1137  return [self _initWithJSNumber:value];
1138 }
1139 
1145 - (id)initWithInt:(int)value
1146 {
1147  return [self _initWithJSNumber:value];
1148 }
1149 
1155 - (id)initWithLong:(long)value
1156 {
1157  return [self _initWithJSNumber:value];
1158 }
1159 
1165 - (id)initWithLongLong:(long long)value
1166 {
1167  return [self _initWithJSNumber:value];
1168 }
1169 
1175 - (id)initWithShort:(short)value
1176 {
1177  return [self _initWithJSNumber:value];
1178 }
1179 
1185 - (id)initWithUnsignedChar:(unsigned char)value
1186 {
1187  return [self _initWithJSNumber:value];
1188 }
1189 
1195 - (id)initWithUnsignedInt:(unsigned)value
1196 {
1197  return [self _initWithJSNumber:value];
1198 }
1199 
1205 - (id)initWithUnsignedLong:(unsigned long)value
1206 {
1207  return [self _initWithJSNumber:value];
1208 }
1209 
1215 - (id)initWithUnsignedLongLong:(unsigned long long)value
1216 {
1217  return [self _initWithJSNumber:value];
1218 }
1219 
1225 - (id)initWithUnsignedShort:(unsigned short)value
1226 {
1227  return [self _initWithJSNumber:value];
1228 }
1229 
1230 - (id)_initWithJSNumber:value
1231 {
1232  if (self = [self init])
1233  _data = CPDecimalMakeWithString(value.toString(), nil);
1234  return self;
1235 }
1236 
1237 @end
1238 
1239 // CPCoding category
1240 var CPDecimalNumberDecimalExponent = @"CPDecimalNumberDecimalExponent",
1241  CPDecimalNumberDecimalIsNegative = @"CPDecimalNumberDecimalIsNegative",
1242  CPDecimalNumberDecimalIsCompact = @"CPDecimalNumberDecimalIsCompact",
1243  CPDecimalNumberDecimalIsNaN = @"CPDecimalNumberDecimalIsNaN",
1244  CPDecimalNumberDecimalMantissa = @"CPDecimalNumberDecimalMantissa";
1245 
1247 
1252 - (id)initWithCoder:(CPCoder)aCoder
1253 {
1254  if (self)
1255  {
1256  var dcm = CPDecimalMakeZero();
1257  dcm._exponent = [aCoder decodeIntForKey:CPDecimalNumberDecimalExponent];
1258  dcm._isNegative = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNegative];
1259  dcm._isCompact = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsCompact];
1260  dcm._isNaN = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNaN];
1261  dcm._mantissa = [aCoder decodeObjectForKey:CPDecimalNumberDecimalMantissa];
1262  [self initWithDecimal:dcm];
1263  }
1264 
1265  return self;
1266 }
1267 
1272 - (void)encodeWithCoder:(CPCoder)aCoder
1273 {
1274  [aCoder encodeInt:_data._exponent forKey:CPDecimalNumberDecimalExponent];
1275  [aCoder encodeBool:_data._isNegative forKey:CPDecimalNumberDecimalIsNegative];
1276  [aCoder encodeBool:_data._isCompact forKey:CPDecimalNumberDecimalIsCompact];
1277  [aCoder encodeBool:_data._isNaN forKey:CPDecimalNumberDecimalIsNaN];
1278  [aCoder encodeObject:_data._mantissa forKey:CPDecimalNumberDecimalMantissa];
1279 }
1280 
1281 @end