FredKiefer@gmx.de
)Version: 1.11
Date: 2004/06/22 22:40:37
Copyright: (C) 2000 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSDecimalNumber.h
- Conforms to:
- NSDecimalNumberBehaviors
Standards:
- MacOS-X
- NotOpenStep
- GNUstep
Class that implements a number of methods for performing decimal arithmetic to arbitrary precision. The behavior in terms of rounding choices and exception handling may be customized using the NSDecimalNumberHandler class, and defaults to [NSDecimalNumberHandler +defaultDecimalNumberHandler] .
Equivalent functionality to the NSDecimalNumber
class may be accessed through functions, mostly named NSDecimalXXX
, e.g., NSDecimalMin()
. Both the class and the functions use a structure called NSDecimal
.
Note that instances of NSDecimalNumber
are immutable.
New instance with given value. Note an NSDecimal may be created using the function NSDecimalFromString() .
New instance by component. Note that the precision of this initializer is limited.
New instance from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy...
methods will return
a result constrained by the current
scale
. Number format is parsed
according to current default locale.
New instance from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy...
methods will return
a result constrained by the current
scale
. Number format is parsed
according to given locale.
Returns the default rounding/precision/exception handling behavior, which is same as [NSDecimalNumberHandler +defaultDecimalNumberHandler] unless it has been explicitly set otherwise.
Return maximum positive value that can be represented.
Return minimum negative value (not the smallest positive value) that can be represented.
Return a fixed value representing an NaN.
Return a constant object with a value of one.
Sets the default rounding/precision/exception handling behavior to the given behavior. If this is not called, behavior defaults to [NSDecimalNumberHandler +defaultDecimalNumberHandler] .
Return a constant object with a value of zero.
Compares with other number, returning less, greater, or equal.
Adds self to decimalNumber and returns new result, using +defaultBehavior for rounding/precision/error handling.
Adds self to decimalNumber and returns new result, using given behavior for rounding/precision/error handling.
Divides self by decimalNumber and returns new result, using +defaultBehavior for rounding/precision/error handling.
Divides self by decimalNumber and returns new result, using given behavior for rounding/precision/error handling.
Multiplies self by decimalNumber and returns new result, using +defaultBehavior for rounding/precision/error handling.
Multiplies self by decimalNumber and returns new result, using given behavior for rounding/precision/error handling.
Multiplies self by given power of 10 and returns new result, using +defaultBehavior for rounding/precision/error handling.
Multiplies self by given power of 10 and returns new result, using given behavior for rounding/precision/error handling.
Raises self to given positive integer power and returns new result, using +defaultBehavior for rounding/precision/error handling.
Raises self to given positive integer power and returns new result, using given behavior for rounding/precision/error handling.
Returns rounded version of underlying decimal.
Subtracts decimalNumber from self and returns new result, using +defaultBehavior for rounding/precision/error handling.
Subtracts decimalNumber from self and returns new result, using given behavior for rounding/precision/error handling.
Return underlying value as an NSDecimal
structure.
Returns string version of number formatted accordng to locale.
Returns underlying value as a double
,
which may be an approximation if precision greater
than the default of 38.
Initialize with given value. Note an NSDecimal may be created using the function NSDecimalFromString() .
Initialize by component. Note that the precision of this initializer is limited.
Initialize from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy...
methods will return
a result constrained by the current
scale
. Number format is parsed
according to current default locale.
Initialize from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy...
methods will return
a result constrained by the current
scale
. Number format is parsed
according to given locale.
Returns the Objective-C type (
@encode(...)
compatible) of the data
contained NSDecimalNumber
, which is
by convention "d" (for double), even though this is not
strictly accurate.
Description forthcoming.
- Declared in:
- Foundation/NSDecimalNumber.h
- Conforms to:
- NSDecimalNumberBehaviors
Standards:
- MacOS-X
- NotOpenStep
- GNUstep
A utility class adopting
<NSDecimalNumberBehaviors>
protocol. Can be used to control
NSDecimalNumber
rounding and exception-handling behavior, by
passing an instance as an argument to any
NSDecimalNumber
method ending with ...Behavior:
.
Constructor setting all behavior. (For more precise control over error handling, create your own class implementing the <NSDecimalNumberBehaviors> protocol.)
Provides an instance implementing the default
behavior for the
NSDecimalNumber
class. 38 decimal digits, rounded to closest
return value (NSRoundPlain
).
Exceptions raised on overflow, underflow, and
divide by zero.
Initializor setting all behavior. (For more precise control over error handling, create your own class implementing the <NSDecimalNumberBehaviors> protocol.)
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
- Declared in:
- Foundation/NSDecimalNumber.h
Standards:
- MacOS-X
- NotOpenStep
- GNUstep
Interface for obtaining an NSDecimalNumber value from an ordinary NSNumber.
Method summary
Obtaining an NSDecimalNumber version of an
ordinary NSNumber.
Returns an NSDecimal
representation of the number. Float and
double values may not be converted exactly
- Declared in:
- Foundation/NSDecimalNumber.h
Standards:
- MacOS-X
- NotOpenStep
- GNUstep
This protocol encapsulates information about how an NSDecimalNumber should round and process exceptions. Usually you can just create objects of the NSDecimalNumberHandler class, which implements this protocol, but if you don't want to use that class you can create your own implementing it.
Method summary
Specifies behavior when, in the course of applying method to leftOperand and rightOperand, an NSDecimalNumber instance encounters given error.
error has four possible constant values:
NSCalculationLossOfPrecision
NSCalculationOverflow
NSCalculationUnderflow
NSCalculationDivideByZero
Behavior on error can be one of the following:
nil
. The calling method will return its value as though no error had occurred. If error is NSCalculationLossOfPrecision
, method will return an imprecise value, constrained to 38 significant digits. If error is NSCalculationUnderflow
or NSCalculationOverflow
, method will return NSDecimalNumber
's notANumber
. You shouldn't return nil
if error is NSDivideByZero
.
NSDecimalNumber
. The calling method will use this as its own return value.
Specifies how
NSDecimalNumber
's decimalNumberBy...
methods round their
return values. This should be set to one of the
following constants:
NSRoundDown
NSRoundUp
NSRoundPlain
NSRoundBankers
Specifies the precision of the values returned by
NSDecimalNumber
's decimalNumberBy...
methods, in terms
of the number of digits allowed after the decimal
point. This can be negative, implying that the
precision should be, e.g., 100's, 1000's, etc..
For unlimited precision, set to
NSDecimalNoScale
.