Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 10 - Transcendental Functions / Financial Functions


compound

You can use the compound function to determine the compound interest earned given an interest rate and period.

double_t compound (double_t rate, double_t periods);
rate
The interest rate (any positive floating-point number).
periods
The number of interest periods (any positive floating-point number). This argument might or might not be an integer.
DESCRIPTION
The compound function computes the compound interest earned.

compound(r,n) = (1+r)n

When rate is a small number, use the function call compound(rate,n) instead of the function call pow((1 + rate),n). The call compound(rate,n) produces a more exact result because it avoids the roundoff error that might occur when the expression
1 + rate is computed.

The compound function is directly applicable to computation of present and future values:

PV = FV×(1+r)-n = FV OVER compound(r,n)

FV = PV×(1+r)n = PV×compound(r,n)

where PV is the amount of money borrowed and FV is the total amount that will be paid on the loan.

EXCEPTIONS
When r and n are finite and nonzero, the result of compound(r,n) might raise one of the following exceptions:

  • inexact (for all finite, nonzero values of r > -1)
  • invalid (if r < -1)
  • divide-by-zero (if r is -1 and n < 0)

SPECIAL CASES
Table 10-33 shows the results when one of the arguments to the compound function is a zero, a NaN, or an Infinity, plus other special cases for the compound function. In this table, r and n are finite, nonzero floating-point numbers.
Special cases for the compound function
OperationResultExceptions raised
compound(r,n) for r < -1NaNInvalid
compound(-1,n) 0 if n > 0None
 + if n < 0Divide-by-zero
compound(+0,n) 1None
compound(r,+0) 1None
 
compound(-0,n) 1None
compound(r,-0) 1None
compound(±0,± ) NaNInvalid
compound(NaN,n) NaN[55]None[56]
compound(r,NaN) NaNNone
compound(+ ,n) + if n > 0None
 0 if n < 0None
compound(r,+ ) + None
compound(- ,n) NaNInvalid
compound(r,- ) 0None

EXAMPLES
z = compound(-2, 12);   /* z = NAN because a negative interest 
                           rate does not make sense. The invalid 
                           exception is raised. */
z = compound(-1, -1);   /* z = +INFINITY because a negative 
                           interest rate and negative loan period 
                           do not make sense. The divide-by-zero 
                           exception is raised. */
z = compound(0, INFINITY);/* z = NAN. The invalid exception is 
                           raised. */

[55] If both arguments are NaNs, the first NaN is returned.
[56] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996