annuity, annuityf, annuityl, compound, compoundf, compoundl - financial functions
cc [ flag ... ] file ... -lsunmath -lm [ library ... ]
double annuity(double r, double n);
float annuityf(float r, float n);
long double annuityl(long double r, long double n);
double compound(double r, double n);
float compoundf(float r, float n);
long double compoundl(long double r, long double n);
These functions are useful in financial computations of the effect of interest at periodic rate r over n periods.
annuity(r, n) computes the present value of annuity factor, (1 - (1+r)**-n) / r. compound(r, n) computes the compound interest factor, (1+r)**n. Both functions return NaN when r <= -1. For sensible values of r and n, these functions are evaluated carefully so as to yield accurate results and avoid spurious floating-point exceptions. In this respect, they are superior to a literal evaluation of the corresponding expressions using the pow(3M) function.
The value of an initial principal P0 after earning interest at periodic rate r for n periods is P = P0 * compound(r, n). Thus a principal amount P0 placed at 5% annual interest compounded quarterly for 30 years would yield
P = P0 * compound(.05 / 4, 30.0 * 4)
Given an initial principal P0, the equivalent periodic payment is p = P0 / annuity(r, n). So a conventional fixed-rate 30-year home loan of amount P0 at 10% annual interest would be amortized by monthly payments in the amount
p = P0 / annuity(.10 / 12, 30.0 * 12)
See attributes(7) for descriptions of the following attributes: