Important: The information in this document is obsolete and should not be used for new development.
annuity
You can use theannuity
function to compute the present and future value of annuities.
double_t annuity (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
Theannuity
function computes the present and future values of annuities.
When
rate
is a small number, use the function callannuity(rate,n)
instead of the expression:
(1 - compound(rate, -n)) / rateThe callannuity(rate,n)
produces a more exact result because it avoids the roundoff errors that might occur when this expression is computed.This function is directly applicable to the computation of present and future values of ordinary annuities:
where PV is the amount of money borrowed, FV is the total amount that will be paid on the loan, and PMT is the amount of one periodic payment.
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 = -1 and n > 0)
SPECIAL CASES
Table 10-34 shows the results when one of the arguments to theannuity
function is a zero, a NaN, or an Infinity, plus other special cases for theannuity
function. In this table, r and n are finite, nonzero floating-point numbers.
Special cases for the annuity
functionOperation Result Exceptions raised for r < -1 NaN Invalid + if n > 0 Divide-by-zero -1 if n < 0 None n None +0 None n None +0 None NaN[57] None[58] NaN None 0 if n > 0 None if n < 0 None 1/r None NaN Invalid None EXAMPLES
z = annuity(-1, 5); /* z = +INFINITY. The divide-by-zero exception is raised. */ z = annuity(-2, -2); /* z = NAN. The invalid exception is raised. */
[57] If both arguments are NaNs, the first NaN is returned.
[58] If the NaN is a signaling NaN, the invalid exception is raised.