date and time created 85/09/06 17:52:50 by zliu
[unix-history] / usr / src / lib / libm / common_source / exp.3
CommitLineData
f15d45ab 1.TH EXP 3M "19 August 1985"
6a716ef9 2.UC 4
f15d45ab 3.ds nn \fINaN\fR
6071f222 4.SH NAME
f15d45ab 5exp, expm1, log, log10, log1p, pow \- exponential, logarithm, power
6071f222
KM
6.SH SYNOPSIS
7.nf
8.B #include <math.h>
9.PP
f15d45ab 10.B double exp(x)
6a716ef9
MAN
11.B double x;
12.PP
f15d45ab 13.B double expm1(x)
6071f222
KM
14.B double x;
15.PP
16.B double log(x)
17.B double x;
18.PP
19.B double log10(x)
20.B double x;
21.PP
f15d45ab
MAN
22.B double log1p(x)
23.B double x;
24.PP
25.B double pow(x,y)
26.B double x,y;
6071f222
KM
27.fi
28.SH DESCRIPTION
6a716ef9 29.PP
f15d45ab
MAN
30Exp returns the exponential function of x.
31.PP
32Expm1 returns exp(x)\-1 accurately even for tiny x.
6a716ef9 33.PP
f15d45ab 34Log returns the natural logarithm of x.
6071f222 35.PP
f15d45ab 36Log10 returns the logarithm of x to base 10.
6071f222 37.PP
f15d45ab
MAN
38Log1p returns log(1+x) accurately even for tiny x.
39.PP
40Pow(x,y) returns
b8757a44 41.if n \
f15d45ab 42x**y.
b8757a44 43.if t \
f15d45ab 44x\u\s8y\s10\d.
6071f222 45.SH SEE ALSO
f15d45ab
MAN
46intro(3M), infnan(3M)
47.SH ERROR (due to Roundoff etc.)
48exp(x), log(x), expm1(x) and log1p(x) are accurate to within
49an \fIulp\fR, and log10(x) to within about 2 \fIulp\fRs;
50an \fIulp\fR is one \fIU\fRnit in the \fIL\fRast \fIP\fRlace.
51The error in pow(x,y) is below about 2 \fIulp\fRs when its
52magnitude is moderate, but increases as pow(x,y) approaches
53the over/underflow thresholds until almost as many bits are
54lost as are occupied by the floating\-point format's exponent
55field; that is 8 bits for VAX D and 11 bits for IEEE 754 Double.
56Moderate values of pow are accurate enough that pow(integer,integer)
57is exact until it is bigger than 2**56 on a VAX, 2**53 for IEEE.
6071f222 58.SH DIAGNOSTICS
f15d45ab
MAN
59Exp, expm1 and pow return the reserved operand on a VAX when the correct
60value would overflow, and they set \fIerrno\fR to ERANGE.
61Pow(x,y) returns the reserved operand on a VAX and sets \fIerrno\fR
62to EDOM when x < 0 and y is not an integer.
6071f222 63.PP
f15d45ab
MAN
64On a VAX, \fIerrno\fR is set to EDOM and the reserved operand is returned
65by log unless x > 0, by log1p unless x > \-1.
7ccdb75f 66.SH NOTES
f15d45ab
MAN
67The functions exp(x)\-1 and log(1+x) are called expm1
68and logp1 in BASIC on the Hewlett\-Packard HP\-71B and APPLE
69Macintosh, EXP1 and LN1 in Pascal, exp1 and log1 in C
70on APPLE Macintoshes, where they have been provided to make
71sure financial calculations of ((1+x)**n\-1)/x, namely
72expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
73They also provide accurate inverse hyperbolic functions.
74.PP
75Pow(x,0) returns x**0 = 1 for all x including x = 0,
76.if n \
77Infinity
78.if t \
7ccdb75f 79\(if
f15d45ab
MAN
80(not found on a VAX), and \*(nn (the reserved
81operand on a VAX). Previous implementations of pow may
82have defined x**0 to be undefined in some or all of these
83cases. Here are reasons for returning x**0 = 1 always:
84.IP (1) \w'\0\0\0\0'u
85Any program that already tests whether x is zero (or
86infinite or \*(nn) before computing x**0 cannot care
87whether 0**0 = 1 or not. Any program that depends
88upon 0**0 to be invalid is dubious anyway since that
89expression's meaning and, if invalid, its consequences
90vary from one computer system to another.
91.IP (2) \w'\0\0\0\0'u
92Some Algebra texts (e.g. Sigler's) define x**0 = 1 for
93all x, including x = 0.
94This is compatible with the convention that accepts a[0]
95as the value of polynomial
96.ce
97p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
98.IP
99at x = 0 rather than reject a[0]\(**0**0 as invalid.
100.IP (3) \w'\0\0\0\0'u
101Analysts will accept 0**0 = 1 despite that x**y can
102approach anything or nothing as x and y approach 0
7ccdb75f 103independently.
f15d45ab
MAN
104The reason for setting 0**0 = 1 anyway is this:
105.IP
106If x(z) and y(z) are \fIany\fR functions analytic (expandable
107in power series) in z around z = 0, and if there
108x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
109.IP (4) \w'\0\0\0\0'u
110If 0**0 = 1, then
111.if n \
112infinity**0 = 1/0**0 = 1 too; and
113.if t \
114\(if**0 = 1/0**0 = 1 too; and
115then \*(nn**0 = 1 too because x**0 = 1 for all finite
116and infinite x, i.e. independently of x.
6a716ef9 117.SH AUTHOR
7ccdb75f 118Kwok\-Choi Ng, W. Kahan