Function

NSDecimalAdd(_:_:_:_:)

Adds two decimal values.

Declaration

func NSDecimalAdd(_ result: UnsafeMutablePointer<Decimal>, _ leftOperand: UnsafePointer<Decimal>, _ rightOperand: UnsafePointer<Decimal>, _ roundingMode: NSDecimalNumber.RoundingMode) -> NSDecimalNumber.CalculationError

Discussion

Adds leftOperand to rightOperand and stores the sum in result. Decimal instances can represent a number with up to 38 significant digits. If a number is more precise than that, it must be rounded off. roundingMode determines how to round it off. There are four possible rounding modes:

The return value indicates whether any machine limitations were encountered in the addition. If none were encountered, the function returns NSCalculationNoError. Otherwise it may return one of the following values: NSCalculationLossOfPrecision, NSCalculationOverflow or NSCalculationUnderflow. For descriptions of all these error conditions, see exceptionDuringOperation(_:error:leftOperand:rightOperand:) in NSDecimalNumberBehaviors.

For more information, see Number and Value Programming Topics.

See Also

Performing Arithmetic Using References

func NSDecimalCompact(UnsafeMutablePointer<Decimal>)

Compacts the decimal structure for efficiency.

typealias Decimal.RoundingMode

An alias for an enumeration that specifies possible rounding modes.

enum NSDecimalNumber.RoundingMode

These constants specify rounding behaviors.

typealias Decimal.CalculationError

An alias for a type that specifies possible calculation errors.