Important: The information in this document is obsolete and should not be used for new development.
compound
You can use thecompound
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
Thecompound
function computes the compound interest earned.
When
rate
is a small number, use the function callcompound(rate,n)
instead of the function callpow((1 + rate),n)
. The callcompound(rate,n)
produces a more exact result because it avoids the roundoff error that might occur when the expression1 + rate
is computed.The
compound
function is directly applicable to computation of present and future values:
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 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 thecompound
function is a zero, a NaN, or an Infinity, plus other special cases for thecompound
function. In this table, r and n are finite, nonzero floating-point numbers.
Special cases for the compound
functionOperation Result Exceptions raised for r < -1 NaN Invalid 0 if n > 0 None + if n < 0 Divide-by-zero 1 None 1 None 1 None 1 None NaN Invalid NaN[55] None[56] NaN None + if n > 0 None 0 if n < 0 None + None NaN Invalid 0 None 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.