34 CPRoundingMode _roundingMode;
36 BOOL _raiseOnExactness;
37 BOOL _raiseOnOverflow;
38 BOOL _raiseOnUnderflow;
39 BOOL _raiseOnDivideByZero;
80 - (id)initWithRoundingMode:(CPRoundingMode)roundingMode scale:(
short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
82 if (
self = [super
init])
84 _roundingMode = roundingMode;
86 _raiseOnExactness = exact;
87 _raiseOnOverflow = overflow;
88 _raiseOnUnderflow = underflow;
89 _raiseOnDivideByZero = divideByZero;
101 + (id)decimalNumberHandlerWithRoundingMode:(CPRoundingMode)roundingMode scale:(
short)scale raiseOnExactness:(BOOL)exact raiseOnOverflow:(BOOL)overflow raiseOnUnderflow:(BOOL)underflow raiseOnDivideByZero:(BOOL)divideByZero
117 + (id)defaultDecimalNumberHandler
148 - (CPRoundingMode)roundingMode
150 return _roundingMode;
184 case CPCalculationNoError:
188 if (_raiseOnOverflow)
195 if (_raiseOnUnderflow)
202 if (_raiseOnExactness)
207 if (_raiseOnDivideByZero)
241 scale:[aCoder decodeIntForKey:CPDecimalNumberHandlerScaleKey]
242 raiseOnExactness:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnExactKey]
243 raiseOnOverflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnOverflowKey]
244 raiseOnUnderflow:[aCoder decodeBoolForKey:CPDecimalNumberHandlerRaiseOnUnderflowKey]
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];
327 return class_createInstance(
self);
345 - (id)initWithDecimal:(CPDecimal)dcm
347 if (
self = [super
init])
365 - (id)initWithMantissa:(
unsigned long long)mantissa exponent:(
short)exponent isNegative:(BOOL)flag
367 if (
self = [
self init])
401 if (
self = [
self init])
428 + (
CPDecimalNumber)decimalNumberWithMantissa:(
unsigned long long)mantissa exponent:(
short)exponent isNegative:(BOOL)flag
442 return [[
self alloc] initWithString:numberValue];
463 + (id)defaultBehavior
535 UID = objj_generateObjectUID();
565 error =
CPDecimalAdd(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
567 if (error > CPCalculationNoError)
602 error =
CPDecimalSubtract(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
604 if (error > CPCalculationNoError)
640 error =
CPDecimalDivide(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
642 if (error > CPCalculationNoError)
677 error =
CPDecimalMultiply(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
679 if (error > CPCalculationNoError)
717 if (error > CPCalculationNoError)
756 error =
CPDecimalPower(result, [
self decimalValue], power, [behavior roundingMode]);
758 if (error > CPCalculationNoError)
780 CPDecimalRound(result, [
self decimalValue], [behavior scale], [behavior roundingMode]);
844 - (CPDecimal)decimalValue
854 - (double)doubleValue
857 return parseFloat([
self stringValue]);
876 return parseInt([
self stringValue]);
886 return parseFloat([
self stringValue]);
896 return parseInt([
self stringValue]);
903 - (
long long)longLongValue
906 return parseInt([
self stringValue]);
916 return parseInt([
self stringValue]);
926 return parseInt([
self stringValue]);
933 - (
unsigned char)unsignedCharValue
936 return parseInt([
self stringValue]);
943 - (
unsigned int)unsignedIntValue
946 return parseInt([
self stringValue]);
953 - (
unsigned long)unsignedLongValue
956 return parseInt([
self stringValue]);
963 - (
unsigned short)unsignedShortValue
966 return parseInt([
self stringValue]);
986 + (id)numberWithBool:(BOOL)aBoolean
988 return [[
self alloc] initWithBool:aBoolean];
996 + (id)numberWithChar:(
char)aChar
998 return [[
self alloc] initWithChar:aChar];
1006 + (id)numberWithDouble:(
double)aDouble
1008 return [[
self alloc] initWithDouble:aDouble];
1016 + (id)numberWithFloat:(
float)aFloat
1018 return [[
self alloc] initWithFloat:aFloat];
1026 + (id)numberWithInt:(
int)anInt
1028 return [[
self alloc] initWithInt:anInt];
1036 + (id)numberWithLong:(
long)aLong
1038 return [[
self alloc] initWithLong:aLong];
1046 + (id)numberWithLongLong:(
long long)aLongLong
1048 return [[
self alloc] initWithLongLong:aLongLong];
1056 + (id)numberWithShort:(
short)aShort
1058 return [[
self alloc] initWithShort:aShort];
1066 + (id)numberWithUnsignedChar:(
unsigned char)aChar
1068 return [[
self alloc] initWithUnsignedChar:aChar];
1076 + (id)numberWithUnsignedInt:(
unsigned)anUnsignedInt
1078 return [[
self alloc] initWithUnsignedInt:anUnsignedInt];
1086 + (id)numberWithUnsignedLong:(
unsigned long)anUnsignedLong
1088 return [[
self alloc] initWithUnsignedLong:anUnsignedLong];
1096 + (id)numberWithUnsignedLongLong:(
unsigned long)anUnsignedLongLong
1106 + (id)numberWithUnsignedShort:(
unsigned short)anUnsignedShort
1108 return [[
self alloc] initWithUnsignedShort:anUnsignedShort];
1116 - (id)initWithBool:(BOOL)value
1118 if (
self = [
self init])
1128 - (id)initWithChar:(
char)value
1130 return [
self _initWithJSNumber:value];
1138 - (id)initWithDouble:(
double)value
1140 return [
self _initWithJSNumber:value];
1148 - (id)initWithFloat:(
float)value
1150 return [
self _initWithJSNumber:value];
1158 - (id)initWithInt:(
int)value
1160 return [
self _initWithJSNumber:value];
1168 - (id)initWithLong:(
long)value
1170 return [
self _initWithJSNumber:value];
1178 - (id)initWithLongLong:(
long long)value
1180 return [
self _initWithJSNumber:value];
1188 - (id)initWithShort:(
short)value
1190 return [
self _initWithJSNumber:value];
1198 - (id)initWithUnsignedChar:(
unsigned char)value
1200 return [
self _initWithJSNumber:value];
1208 - (id)initWithUnsignedInt:(
unsigned)value
1210 return [
self _initWithJSNumber:value];
1218 - (id)initWithUnsignedLong:(
unsigned long)value
1220 return [
self _initWithJSNumber:value];
1228 - (id)initWithUnsignedLongLong:(
unsigned long long)value
1230 return [
self _initWithJSNumber:value];
1238 - (id)initWithUnsignedShort:(
unsigned short)value
1240 return [
self _initWithJSNumber:value];
1243 - (id)_initWithJSNumber:value
1245 if (
self = [
self init])
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];
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];