Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

matherr(3M)

EXP(3M)  —  MATHEMATICAL LIBRARY

NAME

exp, expm1, exp2, exp10, log, log1p, log2, log10, pow, compound, annuity − exponential, logarithm, power

SYNOPSIS

#include <math.h>

double exp(x)
double x;

double expm1(x)
double x;

double exp2(x)
double x;

double exp10(x)
double x;

double log(x)
double x;

double log1p(x)
double x;

double log2(x)
double x;

double log10(x)
double x;

double pow(x, y)
double x, y;

double compound(r, n)
double r, n;

double annuity(r, n)
double r, n;

DESCRIPTION

exp() returns the exponential function e∗∗x.

expm1() returns e∗∗x−1 accurately even for tiny x.

exp2() and exp10() return 2∗∗x and 10∗∗x respectively. 

log() returns the natural logarithm of x.

log1p() returns log(1+x) accurately even for tiny x.

log2() and log10() return the logarithm to base 2 and 10 respectively. 

pow() returns x∗∗y. pow(x ,0.0) is 1 for all x, in conformance with 4.3BSD, as discussed in the Floating-Point Programmer’s Guide. 

compound() and annuity() are functions important in financial computations of the effect of interest at periodic rate r over n periods.  compound(r, n) computes (1+r)∗∗n, the compound interest factor. Given an initial principal P0, its value after n periods is just Pn = P0 ∗ compound(r , n) .  annuity(r, n) computes (1 − (1+r)∗∗−n)/r, the present value of annuity factor.  Given an initial principal P0, the equivalent periodic payment is just p = P0 / annuity(r , n) .  compound() and annuity() are computed using log1p() and expm1() to avoid gratuitous inaccuracy for small-magnitude r. compound() and annuity() are not defined for r <= −1. 

Thus a principal amount P0 placed at 5% annual interest compounded quarterly for 30 years would yield

P30 = P0 ∗ compound(.05/4, 30.0 ∗ 4)

while 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 ALSO

matherr(3M)

DIAGNOSTICS

All these functions handle exceptional arguments in the spirit of ANSI/IEEE Std 754-1985.  Thus for x == ±0, log(x) is −∞ with a division by zero exception; for x < 0, including −∞, log(x) is a quiet NaN with an invalid operation exception; for x == +∞ or a quiet NaN, log(x) is x without exception; for x a signaling NaN, log(x) is a quiet NaN with an invalid operation exception; for x == 1, log(x) is 0 without exception; for any other positive x, log(x) is a normalized number with an inexact exception. 

In addition, exp(), exp2(), exp10(), log(), log2(), log10() and pow() may also set errno and call matherr(3M). 

Solbourne Computer, Inc.  —  24 March 1988

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026