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
103 return [[
self alloc] initWithRoundingMode:roundingMode
105 raiseOnExactness:exact
106 raiseOnOverflow:overflow
107 raiseOnUnderflow:underflow
108 raiseOnDivideByZero: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];
328 return class_createInstance(
self);
346 - (id)initWithDecimal:(CPDecimal)dcm
348 if (
self = [super init])
366 - (id)initWithMantissa:(
unsigned long long)mantissa exponent:(
short)exponent isNegative:(BOOL)flag
368 if (
self = [
self init])
402 if (
self = [
self init])
429 + (
CPDecimalNumber)decimalNumberWithMantissa:(
unsigned long long)mantissa exponent:(
short)exponent isNegative:(BOOL)flag
443 return [[
self alloc] initWithString:numberValue];
464 + (id)defaultBehavior
552 error =
CPDecimalAdd(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
554 if (error > CPCalculationNoError)
589 error =
CPDecimalSubtract(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
591 if (error > CPCalculationNoError)
627 error =
CPDecimalDivide(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
629 if (error > CPCalculationNoError)
664 error =
CPDecimalMultiply(result, [
self decimalValue], [decimalNumber decimalValue], [behavior roundingMode]);
666 if (error > CPCalculationNoError)
704 if (error > CPCalculationNoError)
743 error =
CPDecimalPower(result, [
self decimalValue], power, [behavior roundingMode]);
745 if (error > CPCalculationNoError)
767 CPDecimalRound(result, [
self decimalValue], [behavior scale], [behavior roundingMode]);
831 - (CPDecimal)decimalValue
841 - (double)doubleValue
844 return parseFloat([
self stringValue]);
863 return parseInt([
self stringValue]);
873 return parseFloat([
self stringValue]);
883 return parseInt([
self stringValue]);
890 - (
long long)longLongValue
893 return parseInt([
self stringValue]);
903 return parseInt([
self stringValue]);
913 return parseInt([
self stringValue]);
920 - (
unsigned char)unsignedCharValue
923 return parseInt([
self stringValue]);
930 - (
unsigned int)unsignedIntValue
933 return parseInt([
self stringValue]);
940 - (
unsigned long)unsignedLongValue
943 return parseInt([
self stringValue]);
950 - (
unsigned short)unsignedShortValue
953 return parseInt([
self stringValue]);
973 + (id)numberWithBool:(BOOL)aBoolean
975 return [[
self alloc] initWithBool:aBoolean];
983 + (id)numberWithChar:(
char)aChar
985 return [[
self alloc] initWithChar:aChar];
993 + (id)numberWithDouble:(
double)aDouble
995 return [[
self alloc] initWithDouble:aDouble];
1003 + (id)numberWithFloat:(
float)aFloat
1005 return [[
self alloc] initWithFloat:aFloat];
1013 + (id)numberWithInt:(
int)anInt
1015 return [[
self alloc] initWithInt:anInt];
1023 + (id)numberWithLong:(
long)aLong
1025 return [[
self alloc] initWithLong:aLong];
1033 + (id)numberWithLongLong:(
long long)aLongLong
1035 return [[
self alloc] initWithLongLong:aLongLong];
1043 + (id)numberWithShort:(
short)aShort
1045 return [[
self alloc] initWithShort:aShort];
1053 + (id)numberWithUnsignedChar:(
unsigned char)aChar
1055 return [[
self alloc] initWithUnsignedChar:aChar];
1063 + (id)numberWithUnsignedInt:(
unsigned)anUnsignedInt
1065 return [[
self alloc] initWithUnsignedInt:anUnsignedInt];
1073 + (id)numberWithUnsignedLong:(
unsigned long)anUnsignedLong
1075 return [[
self alloc] initWithUnsignedLong:anUnsignedLong];
1083 + (id)numberWithUnsignedLongLong:(
unsigned long)anUnsignedLongLong
1093 + (id)numberWithUnsignedShort:(
unsigned short)anUnsignedShort
1095 return [[
self alloc] initWithUnsignedShort:anUnsignedShort];
1103 - (id)initWithBool:(BOOL)value
1105 if (
self = [
self init])
1115 - (id)initWithChar:(
char)value
1117 return [
self _initWithJSNumber:value];
1125 - (id)initWithDouble:(
double)value
1127 return [
self _initWithJSNumber:value];
1135 - (id)initWithFloat:(
float)value
1137 return [
self _initWithJSNumber:value];
1145 - (id)initWithInt:(
int)value
1147 return [
self _initWithJSNumber:value];
1155 - (id)initWithLong:(
long)value
1157 return [
self _initWithJSNumber:value];
1165 - (id)initWithLongLong:(
long long)value
1167 return [
self _initWithJSNumber:value];
1175 - (id)initWithShort:(
short)value
1177 return [
self _initWithJSNumber:value];
1185 - (id)initWithUnsignedChar:(
unsigned char)value
1187 return [
self _initWithJSNumber:value];
1195 - (id)initWithUnsignedInt:(
unsigned)value
1197 return [
self _initWithJSNumber:value];
1205 - (id)initWithUnsignedLong:(
unsigned long)value
1207 return [
self _initWithJSNumber:value];
1215 - (id)initWithUnsignedLongLong:(
unsigned long long)value
1217 return [
self _initWithJSNumber:value];
1225 - (id)initWithUnsignedShort:(
unsigned short)value
1227 return [
self _initWithJSNumber:value];
1230 - (id)_initWithJSNumber:value
1232 if (
self = [
self init])
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];
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];