1EXP(3M) EXP(3M)
2
3
4
6 exp, expm1, log, log10, log1p, pow - exponential, logarithm, power
7
9 #include <math.h>
10
11 double exp(x)
12 double x;
13
14 double expm1(x)
15 double x;
16
17 double log(x)
18 double x;
19
20 double log10(x)
21 double x;
22
23 double log1p(x)
24 double x;
25
26 double pow(x,y)
27 double x,y;
28
30 Exp returns the exponential function of x.
31
32 Expm1 returns exp(x)-1 accurately even for tiny x.
33
34 Log returns the natural logarithm of x.
35
36 Log10 returns the logarithm of x to base 10.
37
38 Log1p returns log(1+x) accurately even for tiny x.
39
40 Pow(x,y) returns x**y.
41
43 exp(x), log(x), expm1(x) and log1p(x) are accurate to within an ulp,
44 and log10(x) to within about 2 ulps; an ulp is one Unit in the Last
45 Place. The error in pow(x,y) is below about 2 ulps when its magnitude
46 is moderate, but increases as pow(x,y) approaches the over/underflow
47 thresholds until almost as many bits could be lost as are occupied by
48 the floating-point format's exponent field; that is 8 bits for VAX D
49 and 11 bits for IEEE 754 Double. No such drastic loss has been exposed
50 by testing; the worst errors observed have been below 20 ulps for VAX
51 D, 300 ulps for IEEE 754 Double. Moderate values of pow are accurate
52 enough that pow(integer,integer) is exact until it is bigger than 2**56
53 on a VAX, 2**53 for IEEE 754.
54
56 Exp, expm1 and pow return the reserved operand on a VAX when the cor‐
57 rect value would overflow, and they set errno to ERANGE. Pow(x,y)
58 returns the reserved operand on a VAX and sets errno to EDOM when x < 0
59 and y is not an integer.
60
61 On a VAX, errno is set to EDOM and the reserved operand is returned by
62 log unless x > 0, by log1p unless x > -1.
63
65 The functions exp(x)-1 and log(1+x) are called expm1 and logp1 in BASIC
66 on the Hewlett-Packard HP-71B and APPLE Macintosh, EXP1 and LN1 in Pas‐
67 cal, exp1 and log1 in C on APPLE Macintoshes, where they have been pro‐
68 vided to make sure financial calculations of ((1+x)**n-1)/x, namely
69 expm1(n∗log1p(x))/x, will be accurate when x is tiny. They also pro‐
70 vide accurate inverse hyperbolic functions.
71
72 Pow(x,0) returns x**0 = 1 for all x including x = 0, Infinity (not
73 found on a VAX), and NaN (the reserved operand on a VAX). Previous
74 implementations of pow may have defined x**0 to be undefined in some or
75 all of these cases. Here are reasons for returning x**0 = 1 always:
76
77 (1) Any program that already tests whether x is zero (or infinite or
78 NaN) before computing x**0 cannot care whether 0**0 = 1 or not. Any
79 program that depends upon 0**0 to be invalid is dubious anyway
80 since that expression's meaning and, if invalid, its consequences
81 vary from one computer system to another.
82
83 (2) Some Algebra texts (e.g. Sigler's) define x**0 = 1 for all x,
84 including x = 0. This is compatible with the convention that
85 accepts a[0] as the value of polynomial
86 p(x) = a[0]∗x**0 + a[1]∗x**1 + a[2]∗x**2 +...+ a[n]∗x**n
87
88 at x = 0 rather than reject a[0]∗0**0 as invalid.
89
90 (3) Analysts will accept 0**0 = 1 despite that x**y can approach any‐
91 thing or nothing as x and y approach 0 independently. The reason
92 for setting 0**0 = 1 anyway is this:
93
94 If x(z) and y(z) are any functions analytic (expandable in power
95 series) in z around z = 0, and if there x(0) = y(0) = 0, then
96 x(z)**y(z) → 1 as z → 0.
97
98 (4) If 0**0 = 1, then infinity**0 = 1/0**0 = 1 too; and then NaN**0 = 1
99 too because x**0 = 1 for all finite and infinite x, i.e., indepen‐
100 dently of x.
101
103 math(3M), infnan(3M)
104
106 Kwok-Choi Ng, W. Kahan
107
108
109
1104th Berkeley Distribution May 27, 1986 EXP(3M)