API  0.9.8
 All Classes Files Functions Variables Typedefs 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 
32 {
33  CPRoundingMode _roundingMode;
34  short _scale;
35  BOOL _raiseOnExactness;
36  BOOL _raiseOnOverflow;
37  BOOL _raiseOnUnderflow;
38  BOOL _raiseOnDivideByZero;
39 }
40 
41 // initializers
48 - (id)init
49 {
50  return [self initWithRoundingMode:CPRoundPlain
51  scale:0
53  raiseOnOverflow:YES
56 }
57 
79 - (id)initWithRoundingMode:(CPRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
80 {
81  if (self = [super init])
82  {
83  _roundingMode = roundingMode;
84  _scale = scale;
85  _raiseOnExactness = exact;
86  _raiseOnOverflow = overflow;
87  _raiseOnUnderflow = underflow;
88  _raiseOnDivideByZero = divideByZero;
89  }
90 
91  return self;
92 }
93 
94 // class methods
100 + (id)decimalNumberHandlerWithRoundingMode:(CPRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
101 {
102  return [[self alloc] initWithRoundingMode:roundingMode
103  scale:scale
104  raiseOnExactness:exact
105  raiseOnOverflow:overflow
106  raiseOnUnderflow:underflow
107  raiseOnDivideByZero:divideByZero];
108 }
109 
116 + (id)defaultDecimalNumberHandler
117 {
118  if (!CPDefaultDcmHandler)
120 
121  return CPDefaultDcmHandler;
122 }
123 
124 @end
125 
126 // CPDecimalNumberBehaviors protocol
127 
129 
130 - (CPRoundingMode)roundingMode;
131 
132 - (short)scale;
133  // The scale could return NO_SCALE for no defined scale.
134 
135 - (CPDecimalNumber)exceptionDuringOperation:(SEL)operation error:(CPCalculationError)error leftOperand:(CPDecimalNumber)leftOperand rightOperand:(CPDecimalNumber)rightOperand;
136  // Receiver can raise, return a new value, or return nil to ignore the exception.
137 
138 @end
139 
141 
147 - (CPRoundingMode)roundingMode
148 {
149  return _roundingMode;
150 }
151 
156 - (short)scale
157 {
158  return _scale;
159 }
160 
179 - (CPDecimalNumber)exceptionDuringOperation:(SEL)operation error:(CPCalculationError)error leftOperand:(CPDecimalNumber)leftOperand rightOperand:(CPDecimalNumber)rightOperand
180 {
181  switch (error)
182  {
183  case CPCalculationNoError:
184  break;
185 
187  if (_raiseOnOverflow)
188  [CPException raise:CPDecimalNumberOverflowException reason:("A CPDecimalNumber overflow has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
189  else
190  return [CPDecimalNumber notANumber];
191  break;
192 
194  if (_raiseOnUnderflow)
195  [CPException raise:CPDecimalNumberUnderflowException reason:("A CPDecimalNumber underflow has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
196  else
197  return [CPDecimalNumber notANumber];
198  break;
199 
201  if (_raiseOnExactness)
202  [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 + "')") ];
203  break;
204 
206  if (_raiseOnDivideByZero)
207  [CPException raise:CPDecimalNumberDivideByZeroException reason:("A CPDecimalNumber divide by zero has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')") ];
208  else
209  return [CPDecimalNumber notANumber]; // Div by zero returns NaN
210  break;
211 
212  default:
213  [CPException raise:CPInvalidArgumentException reason:("An unknown CPDecimalNumber error has occurred. (Left operand= '" + [leftOperand descriptionWithLocale:nil] + "' Right operand= '" + [rightOperand descriptionWithLocale:nil] + "' Selector= '" + operation + "')")];
214  }
215 
216  return nil;
217 }
218 
219 @end
220 
221 // CPCoding category
222 var CPDecimalNumberHandlerRoundingModeKey = @"CPDecimalNumberHandlerRoundingModeKey",
223  CPDecimalNumberHandlerScaleKey = @"CPDecimalNumberHandlerScaleKey",
224  CPDecimalNumberHandlerRaiseOnExactKey = @"CPDecimalNumberHandlerRaiseOnExactKey",
225  CPDecimalNumberHandlerRaiseOnOverflowKey = @"CPDecimalNumberHandlerRaiseOnOverflowKey",
226  CPDecimalNumberHandlerRaiseOnUnderflowKey = @"CPDecimalNumberHandlerRaiseOnUnderflowKey",
227  CPDecimalNumberHandlerDivideByZeroKey = @"CPDecimalNumberHandlerDivideByZeroKey";
228 
230 
235 - (id)initWithCoder:(CPCoder)aCoder
236 {
237  if (self)
238  {
239  [self initWithRoundingMode:[aCoder decodeIntForKey:CPDecimalNumberHandlerRoundingModeKey]
240  scale:[aCoder decodeIntForKey:CPDecimalNumberHandlerScaleKey]
241  raiseOnExactness:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnExactKey]
242  raiseOnOverflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnOverflowKey]
243  raiseOnUnderflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnUnderflowKey]
244  raiseOnDivideByZero:[aCoder decodeBoolForKey:CPDecimalNumberHandlerDivideByZeroKey]];
245  }
246 
247  return self;
248 }
249 
254 - (void)encodeWithCoder:(CPCoder)aCoder
255 {
256  [aCoder encodeInt:[self roundingMode] forKey:CPDecimalNumberHandlerRoundingModeKey];
257  [aCoder encodeInt:[self scale] forKey:CPDecimalNumberHandlerScaleKey];
258  [aCoder encodeBool:_raiseOnExactness forKey:CPDecimalNumberHandlerRaiseOnExactKey];
259  [aCoder encodeBool:_raiseOnOverflow forKey:CPDecimalNumberHandlerRaiseOnOverflowKey];
260  [aCoder encodeBool:_raiseOnUnderflow forKey:CPDecimalNumberHandlerRaiseOnUnderflowKey];
261  [aCoder encodeBool:_raiseOnDivideByZero forKey:CPDecimalNumberHandlerDivideByZeroKey];
262 }
263 
264 @end
265 
312 @implementation CPDecimalNumber : CPNumber
313 {
314  CPDecimal _data;
315 }
316 
323 + (id)alloc
324 {
325  // overriding alloc means CPDecimalNumbers are not toll free bridged
326  return class_createInstance(self);
327 }
328 
329 // initializers
334 - (id)init
335 {
336  return [self initWithDecimal:CPDecimalMakeNaN()];
337 }
338 
344 - (id)initWithDecimal:(CPDecimal)dcm
345 {
346  if (self = [super init])
347  _data = CPDecimalCopy(dcm);
348 
349  return self;
350 }
351 
364 - (id)initWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
365 {
366  if (self = [self init])
367  {
368  if (flag)
369  mantissa *= -1;
370 
371  _data = CPDecimalMakeWithParts(mantissa, exponent);
372  }
373 
374  return self;
375 }
376 
384 - (id)initWithString:(CPString)numberValue
385 {
386  return [self initWithString:numberValue locale:nil];
387 }
388 
398 - (id)initWithString:(CPString)numberValue locale:(CPDictionary)locale
399 {
400  if (self = [self init])
401  {
402  _data = CPDecimalMakeWithString(numberValue, locale);
403  }
404 
405  return self;
406 }
407 
408 // class methods
414 + (CPDecimalNumber)decimalNumberWithDecimal:(CPDecimal)dcm
415 {
416  return [[self alloc] initWithDecimal:dcm];
417 }
418 
427 + (CPDecimalNumber)decimalNumberWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag
428 {
429  return [[self alloc] initWithMantissa:mantissa exponent:exponent isNegative:flag];
430 }
431 
439 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue
440 {
441  return [[self alloc] initWithString:numberValue];
442 }
443 
453 + (CPDecimalNumber)decimalNumberWithString:(CPString)numberValue locale:(CPDictionary)locale
454 {
455  return [[self alloc] initWithString:numberValue locale:locale];
456 }
457 
462 + (id)defaultBehavior
463 {
465 }
466 
472 + (void)setDefaultBehavior:(id <CPDecimalNumberBehaviors>)behavior
473 {
474  CPDefaultDcmHandler = behavior;
475 }
476 
483 + (CPDecimalNumber)maximumDecimalNumber
484 {
485  return [[self alloc] initWithDecimal:_CPDecimalMakeMaximum()];
486 }
487 
494 + (CPDecimalNumber)minimumDecimalNumber
495 {
496  return [[self alloc] initWithDecimal:_CPDecimalMakeMinimum()];
497 }
498 
503 + (CPDecimalNumber)notANumber
504 {
505  return [[self alloc] initWithDecimal:CPDecimalMakeNaN()];
506 }
507 
513 {
514  return [[self alloc] initWithDecimal:CPDecimalMakeZero()];
515 }
516 
522 {
523  return [[self alloc] initWithDecimal:CPDecimalMakeOne()];
524 }
525 
526 // instance methods
534 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber
535 {
537 }
538 
547 - (CPDecimalNumber)decimalNumberByAdding:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
548 {
549  var result = CPDecimalMakeZero(),
550  error = CPDecimalAdd(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
551 
552  if (error > CPCalculationNoError)
553  {
554  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
555  if (res != nil)
556  return res;
557  }
558 
560 }
561 
570 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber
571 {
573 }
574 
584 - (CPDecimalNumber)decimalNumberBySubtracting:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
585 {
586  var result = CPDecimalMakeZero(),
587  error = CPDecimalSubtract(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
588 
589  if (error > CPCalculationNoError)
590  {
591  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
592 
593  if (res != nil)
594  return res;
595  }
596 
598 }
599 
608 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber
609 {
611 }
612 
622 - (CPDecimalNumber)decimalNumberByDividingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
623 {
624  var result = CPDecimalMakeZero(),
625  error = CPDecimalDivide(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
626 
627  if (error > CPCalculationNoError)
628  {
629  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
630  if (res != nil)
631  return res;
632  }
633 
635 }
636 
645 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber
646 {
648 }
649 
659 - (CPDecimalNumber)decimalNumberByMultiplyingBy:(CPDecimalNumber)decimalNumber withBehavior:(id <CPDecimalNumberBehaviors>)behavior
660 {
661  var result = CPDecimalMakeZero(),
662  error = CPDecimalMultiply(result, [self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
663 
664  if (error > CPCalculationNoError)
665  {
666  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:decimalNumber];
667 
668  if (res != nil)
669  return res;
670  }
671 
673 }
674 
683 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power
684 {
686 }
687 
697 - (CPDecimalNumber)decimalNumberByMultiplyingByPowerOf10:(short)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
698 {
699  var result = CPDecimalMakeZero(),
700  error = CPDecimalMultiplyByPowerOf10(result, [self decimalValue], power, [behavior roundingMode]);
701 
702  if (error > CPCalculationNoError)
703  {
704  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
705 
706  if (res != nil)
707  return res;
708  }
709 
711 }
712 
721 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power
722 {
724 }
725 
735 - (CPDecimalNumber)decimalNumberByRaisingToPower:(unsigned)power withBehavior:(id <CPDecimalNumberBehaviors>)behavior
736 {
737  if (power < 0)
738  return [behavior exceptionDuringOperation:_cmd error:-1 leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
739 
740  var result = CPDecimalMakeZero(),
741  error = CPDecimalPower(result, [self decimalValue], power, [behavior roundingMode]);
742 
743  if (error > CPCalculationNoError)
744  {
745  var res = [behavior exceptionDuringOperation:_cmd error:error leftOperand:self rightOperand:[CPDecimalNumber decimalNumberWithString:power.toString()]];
746 
747  if (res != nil)
748  return res;
749  }
750 
752 }
753 
761 - (CPDecimalNumber)decimalNumberByRoundingAccordingToBehavior:(id <CPDecimalNumberBehaviors>)behavior
762 {
763  var result = CPDecimalMakeZero();
764 
765  CPDecimalRound(result, [self decimalValue], [behavior scale], [behavior roundingMode]);
766 
768 }
769 
777 - (CPComparisonResult)compare:(CPNumber)aNumber
778 {
779  // aNumber type is checked to convert if appropriate
780  if (![aNumber isKindOfClass:[CPDecimalNumber class]])
781  aNumber = [CPDecimalNumber decimalNumberWithString:aNumber.toString()];
782 
783  return CPDecimalCompare([self decimalValue], [aNumber decimalValue]);
784 }
785 
790 - (CPString)objCType
791 {
792  return @"d";
793 }
794 
799 - (CPString)description
800 {
801  return [self descriptionWithLocale:nil]
802 }
803 
810 - (CPString)descriptionWithLocale:(CPDictionary)locale
811 {
812  return CPDecimalString(_data, locale);
813 }
814 
819 - (CPString)stringValue
820 {
821  return [self description];
822 }
823 
829 - (CPDecimal)decimalValue
830 {
831  return CPDecimalCopy(_data);
832 }
833 
834 // Type Conversion Methods
839 - (double)doubleValue
840 {
841  // FIXME: locale support / bounds check?
842  return parseFloat([self stringValue]);
843 }
844 
849 - (BOOL)boolValue
850 {
851  return (CPDecimalIsZero(_data))?NO:YES;
852 }
853 
858 - (char)charValue
859 {
860  // FIXME: locale support / bounds check?
861  return parseInt([self stringValue]);
862 }
863 
868 - (float)floatValue
869 {
870  // FIXME: locale support / bounds check?
871  return parseFloat([self stringValue]);
872 }
873 
878 - (int)intValue
879 {
880  // FIXME: locale support / bounds check?
881  return parseInt([self stringValue]);
882 }
883 
888 - (long long)longLongValue
889 {
890  // FIXME: locale support / bounds check?
891  return parseInt([self stringValue]);
892 }
893 
898 - (long)longValue
899 {
900  // FIXME: locale support / bounds check?
901  return parseInt([self stringValue]);
902 }
903 
908 - (short)shortValue
909 {
910  // FIXME: locale support / bounds check?
911  return parseInt([self stringValue]);
912 }
913 
918 - (unsigned char)unsignedCharValue
919 {
920  // FIXME: locale support / bounds check?
921  return parseInt([self stringValue]);
922 }
923 
928 - (unsigned int)unsignedIntValue
929 {
930  // FIXME: locale support / bounds check?
931  return parseInt([self stringValue]);
932 }
933 
938 - (unsigned long)unsignedLongValue
939 {
940  // FIXME: locale support / bounds check?
941  return parseInt([self stringValue]);
942 }
943 
948 - (unsigned short)unsignedShortValue
949 {
950  // FIXME: locale support / bounds check?
951  return parseInt([self stringValue]);
952 }
953 
954 // CPNumber inherited methods
961 - (BOOL)isEqualToNumber:(CPNumber)aNumber
962 {
963  return (CPDecimalCompare(CPDecimalMakeWithString(aNumber.toString(),nil), _data) == CPOrderedSame)?YES:NO;
964 }
965 
971 + (id)numberWithBool:(BOOL)aBoolean
972 {
973  return [[self alloc] initWithBool:aBoolean];
974 }
975 
981 + (id)numberWithChar:(char)aChar
982 {
983  return [[self alloc] initWithChar:aChar];
984 }
985 
991 + (id)numberWithDouble:(double)aDouble
992 {
993  return [[self alloc] initWithDouble:aDouble];
994 }
995 
1001 + (id)numberWithFloat:(float)aFloat
1002 {
1003  return [[self alloc] initWithFloat:aFloat];
1004 }
1005 
1011 + (id)numberWithInt:(int)anInt
1012 {
1013  return [[self alloc] initWithInt:anInt];
1014 }
1015 
1021 + (id)numberWithLong:(long)aLong
1022 {
1023  return [[self alloc] initWithLong:aLong];
1024 }
1025 
1031 + (id)numberWithLongLong:(long long)aLongLong
1032 {
1033  return [[self alloc] initWithLongLong:aLongLong];
1034 }
1035 
1041 + (id)numberWithShort:(short)aShort
1042 {
1043  return [[self alloc] initWithShort:aShort];
1044 }
1045 
1051 + (id)numberWithUnsignedChar:(unsigned char)aChar
1052 {
1053  return [[self alloc] initWithUnsignedChar:aChar];
1054 }
1055 
1061 + (id)numberWithUnsignedInt:(unsigned)anUnsignedInt
1062 {
1063  return [[self alloc] initWithUnsignedInt:anUnsignedInt];
1064 }
1065 
1071 + (id)numberWithUnsignedLong:(unsigned long)anUnsignedLong
1072 {
1073  return [[self alloc] initWithUnsignedLong:anUnsignedLong];
1074 }
1075 
1081 + (id)numberWithUnsignedLongLong:(unsigned long)anUnsignedLongLong
1082 {
1083  return [[self alloc] initWithUnsignedLongLong:anUnsignedLongLong];
1084 }
1085 
1091 + (id)numberWithUnsignedShort:(unsigned short)anUnsignedShort
1092 {
1093  return [[self alloc] initWithUnsignedShort:anUnsignedShort];
1094 }
1095 
1101 - (id)initWithBool:(BOOL)value
1102 {
1103  if (self = [self init])
1104  _data = CPDecimalMakeWithParts((value)?1:0, 0);
1105  return self;
1106 }
1107 
1113 - (id)initWithChar:(char)value
1114 {
1115  return [self _initWithJSNumber:value];
1116 }
1117 
1123 - (id)initWithDouble:(double)value
1124 {
1125  return [self _initWithJSNumber:value];
1126 }
1127 
1133 - (id)initWithFloat:(float)value
1134 {
1135  return [self _initWithJSNumber:value];
1136 }
1137 
1143 - (id)initWithInt:(int)value
1144 {
1145  return [self _initWithJSNumber:value];
1146 }
1147 
1153 - (id)initWithLong:(long)value
1154 {
1155  return [self _initWithJSNumber:value];
1156 }
1157 
1163 - (id)initWithLongLong:(long long)value
1164 {
1165  return [self _initWithJSNumber:value];
1166 }
1167 
1173 - (id)initWithShort:(short)value
1174 {
1175  return [self _initWithJSNumber:value];
1176 }
1177 
1183 - (id)initWithUnsignedChar:(unsigned char)value
1184 {
1185  return [self _initWithJSNumber:value];
1186 }
1187 
1193 - (id)initWithUnsignedInt:(unsigned)value
1194 {
1195  return [self _initWithJSNumber:value];
1196 }
1197 
1203 - (id)initWithUnsignedLong:(unsigned long)value
1204 {
1205  return [self _initWithJSNumber:value];
1206 }
1207 
1213 - (id)initWithUnsignedLongLong:(unsigned long long)value
1214 {
1215  return [self _initWithJSNumber:value];
1216 }
1217 
1223 - (id)initWithUnsignedShort:(unsigned short)value
1224 {
1225  return [self _initWithJSNumber:value];
1226 }
1227 
1228 - (id)_initWithJSNumber:value
1229 {
1230  if (self = [self init])
1231  _data = CPDecimalMakeWithString(value.toString(), nil);
1232  return self;
1233 }
1234 
1235 @end
1236 
1237 // CPCoding category
1238 var CPDecimalNumberDecimalExponent = @"CPDecimalNumberDecimalExponent",
1239  CPDecimalNumberDecimalIsNegative = @"CPDecimalNumberDecimalIsNegative",
1240  CPDecimalNumberDecimalIsCompact = @"CPDecimalNumberDecimalIsCompact",
1241  CPDecimalNumberDecimalIsNaN = @"CPDecimalNumberDecimalIsNaN",
1242  CPDecimalNumberDecimalMantissa = @"CPDecimalNumberDecimalMantissa";
1243 
1245 
1250 - (id)initWithCoder:(CPCoder)aCoder
1251 {
1252  if (self)
1253  {
1254  var dcm = CPDecimalMakeZero();
1255  dcm._exponent = [aCoder decodeIntForKey:CPDecimalNumberDecimalExponent];
1256  dcm._isNegative = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNegative];
1257  dcm._isCompact = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsCompact];
1258  dcm._isNaN = [aCoder decodeBoolForKey:CPDecimalNumberDecimalIsNaN];
1259  dcm._mantissa = [aCoder decodeObjectForKey:CPDecimalNumberDecimalMantissa];
1260  [self initWithDecimal:dcm];
1261  }
1262 
1263  return self;
1264 }
1265 
1270 - (void)encodeWithCoder:(CPCoder)aCoder
1271 {
1272  [aCoder encodeInt:_data._exponent forKey:CPDecimalNumberDecimalExponent];
1273  [aCoder encodeBool:_data._isNegative forKey:CPDecimalNumberDecimalIsNegative];
1274  [aCoder encodeBool:_data._isCompact forKey:CPDecimalNumberDecimalIsCompact];
1275  [aCoder encodeBool:_data._isNaN forKey:CPDecimalNumberDecimalIsNaN];
1276  [aCoder encodeObject:_data._mantissa forKey:CPDecimalNumberDecimalMantissa];
1277 }
1278 
1279 @end