xref: /csrg-svn/lib/libm/common_source/exp.3 (revision 48352)
1*48352Scael.\" Copyright (c) 1985, 1991 Regents of the University of California.
2*48352Scael.\" All rights reserved.
324694Smckusick.\"
4*48352Scael.\" %sccs.include.redist.man%
524694Smckusick.\"
6*48352Scael.\"     @(#)exp.3	6.10 (Berkeley) 04/19/91
7*48352Scael.\"
8*48352Scael.Dd
9*48352Scael.Dt EXP 3
10*48352Scael.Os BSD 4
11*48352Scael.Sh NAME
12*48352Scael.Nm exp ,
13*48352Scael.Nm expm1 ,
14*48352Scael.Nm log ,
15*48352Scael.Nm log10 ,
16*48352Scael.Nm log1p ,
17*48352Scael.Nm pow
18*48352Scael.Nd exponential, logarithm, power functions
19*48352Scael.Sh SYNOPSIS
20*48352Scael.Fd #include <math.h>
21*48352Scael.Ft double
22*48352Scael.Fn exp "double x"
23*48352Scael.Ft double
24*48352Scael.Fn expm1 "double x"
25*48352Scael.Ft double
26*48352Scael.Fn log "double x"
27*48352Scael.Ft double
28*48352Scael.Fn log10 "double x"
29*48352Scael.Ft double
30*48352Scael.Fn log1p "double x"
31*48352Scael.Ft double
32*48352Scael.Fn pow "double x" "double y"
33*48352Scael.Sh DESCRIPTION
34*48352ScaelThe
35*48352Scael.Fn exp
36*48352Scaelfunction computes the exponential value of the given argument
37*48352Scael.Fa x .
38*48352Scael.Pp
39*48352ScaelThe
40*48352Scael.Fn expm1
41*48352Scaelfunction computes the value exp(x)\-1 accurately even for tiny argument
42*48352Scael.Fa x .
43*48352Scael.Pp
44*48352ScaelThe
45*48352Scael.Fn log
46*48352Scaelfunction computes the value for the natural logarithm of
47*48352Scaelthe argument x.
48*48352Scael.Pp
49*48352ScaelThe
50*48352Scael.Fn log10
51*48352Scaelfunction computes the value for the logarithm of
52*48352Scaelargument
53*48352Scael.Fa x
54*48352Scaelto base 10.
55*48352Scael.Pp
56*48352ScaelThe
57*48352Scael.Fn log1p
58*48352Scaelfunction computes
59*48352Scaelthe value of log(1+x) accurately even for tiny argument
60*48352Scael.Fa x .
61*48352Scael.Pp
62*48352ScaelThe
63*48352Scael.Fn pow
64*48352Scaelcomputes the value
65*48352Scaelof
66*48352Scael.Ar x
67*48352Scaelto the exponent
68*48352Scael.Ar y .
69*48352Scael.Sh ERROR (due to Roundoff etc.)
7024371Smiriamexp(x), log(x), expm1(x) and log1p(x) are accurate to within
71*48352Scaelan
72*48352Scael.Em up ,
73*48352Scaeland log10(x) to within about 2
74*48352Scael.Em ups ;
75*48352Scaelan
76*48352Scael.Em up
77*48352Scaelis one
78*48352Scael.Em Unit
79*48352Scaelin the
80*48352Scael.Em Last
81*48352Scael.Em Place .
82*48352ScaelThe error in
83*48352Scael.Fn pow x y
84*48352Scaelis below about 2
85*48352Scael.Em ups
86*48352Scaelwhen its
87*48352Scaelmagnitude is moderate, but increases as
88*48352Scael.Fn pow x y
89*48352Scaelapproaches
9024694Smckusickthe over/underflow thresholds until almost as many bits could be
9124371Smiriamlost as are occupied by the floating\-point format's exponent
92*48352Scaelfield; that is 8 bits for
93*48352Scael.Tn "VAX D"
94*48352Scaeland 11 bits for IEEE 754 Double.
9524694SmckusickNo such drastic loss has been exposed by testing; the worst
96*48352Scaelerrors observed have been below 20
97*48352Scael.Em ups
98*48352Scaelfor
99*48352Scael.Tn "VAX D" ,
100*48352Scael300
101*48352Scael.Em ups
102*48352Scaelfor
103*48352Scael.Tn IEEE
104*48352Scael754 Double.
105*48352ScaelModerate values of
106*48352Scael.Fn pow
107*48352Scaelare accurate enough that
108*48352Scael.Fn pow integer integer
109*48352Scaelis exact until it is bigger than 2**56 on a
110*48352Scael.Tn VAX ,
111*48352Scael2**53 for
112*48352Scael.Tn IEEE
113*48352Scael754.
114*48352Scael.Sh RETURN VALUES
115*48352ScaelThese functions will return the approprate computation unless an error
116*48352Scaeloccurs or an argument is out of range.
117*48352ScaelThe functions
118*48352Scael.Fn exp ,
119*48352Scael.Fn expm1
120*48352Scaeland
121*48352Scael.Fn pow
122*48352Scaeldetect if the computed value will overflow,
123*48352Scaelset the global variable
124*48352Scael.Va errno to
125*48352Scael.Er RANGE
126*48352Scaeland cause a reserved operand fault on a
127*48352Scael.Tn VAX
128*48352Scaelor
129*48352Scael.Tn Tahoe .
130*48352ScaelThe function
131*48352Scael.Fn pow x y
132*48352Scaelchecks to see if
133*48352Scael.Fa x
134*48352Scael< 0 and
135*48352Scael.Fa y
136*48352Scaelis not an integer, in the event this is true,
137*48352Scaelthe global variable
138*48352Scael.Va errno
139*48352Scaelis set to
140*48352Scael.Er EDOM
141*48352Scaeland on the
142*48352Scael.Tn VAX
143*48352Scaeland
144*48352Scael.Tn Tahoe
145*48352Scaelgenerate a reserved operand fault.
146*48352ScaelOn a
147*48352Scael.Tn VAX
148*48352Scaeland
149*48352Scael.Tn Tahoe ,
150*48352Scael.Va errno
151*48352Scaelis set to
152*48352Scael.Er EDOM
153*48352Scaeland the reserved operand is returned
154*48352Scaelby log unless
155*48352Scael.Fa x
156*48352Scael> 0, by
157*48352Scael.Fn log1p
158*48352Scaelunless
159*48352Scael.Fa x
160*48352Scael> \-1.
161*48352Scael.Sh NOTES
162*48352ScaelThe functions exp(x)\-1 and log(1+x) are called
163*48352Scaelexpm1 and logp1 in
164*48352Scael.Tn BASIC
165*48352Scaelon the Hewlett\-Packard
166*48352Scael.Tn HP Ns \-71B
167*48352Scaeland
168*48352Scael.Tn APPLE
169*48352ScaelMacintosh,
170*48352Scael.Tn EXP1
171*48352Scaeland
172*48352Scael.Tn LN1
173*48352Scaelin Pascal, exp1 and log1 in C
174*48352Scaelon
175*48352Scael.Tn APPLE
176*48352ScaelMacintoshes, where they have been provided to make
17724371Smiriamsure financial calculations of ((1+x)**n\-1)/x, namely
17824371Smiriamexpm1(n\(**log1p(x))/x, will be accurate when x is tiny.
17924371SmiriamThey also provide accurate inverse hyperbolic functions.
180*48352Scael.Pp
181*48352ScaelThe function
182*48352Scael.Fn pow x 0
183*48352Scaelreturns x**0 = 1 for all x including x = 0,
18424371Smiriam.if n \
18524371SmiriamInfinity
18624371Smiriam.if t \
18723565Smiriam\(if
188*48352Scael(not found on a
189*48352Scael.Tn VAX ) ,
190*48352Scaeland
191*48352Scael.Em NaN
192*48352Scael(the reserved
193*48352Scaeloperand on a
194*48352Scael.Tn VAX ) .  Previous implementations of pow may
19524371Smiriamhave defined x**0 to be undefined in some or all of these
19624371Smiriamcases.  Here are reasons for returning x**0 = 1 always:
197*48352Scael.Bl -enum -width indent
198*48352Scael.It
19924371SmiriamAny program that already tests whether x is zero (or
20024371Smiriaminfinite or \*(nn) before computing x**0 cannot care
20124371Smiriamwhether 0**0 = 1 or not. Any program that depends
20224371Smiriamupon 0**0 to be invalid is dubious anyway since that
20324371Smiriamexpression's meaning and, if invalid, its consequences
20424371Smiriamvary from one computer system to another.
205*48352Scael.It
20624371SmiriamSome Algebra texts (e.g. Sigler's) define x**0 = 1 for
20724371Smiriamall x, including x = 0.
20824371SmiriamThis is compatible with the convention that accepts a[0]
20924371Smiriamas the value of polynomial
210*48352Scael.Bd -literal -offset indent
21124371Smiriamp(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
212*48352Scael.Ed
213*48352Scael.Pp
21424371Smiriamat x = 0 rather than reject a[0]\(**0**0 as invalid.
215*48352Scael.It
21624371SmiriamAnalysts will accept 0**0 = 1 despite that x**y can
21724371Smiriamapproach anything or nothing as x and y approach 0
21823565Smiriamindependently.
21924371SmiriamThe reason for setting 0**0 = 1 anyway is this:
220*48352Scael.Bd -filled -offset indent
221*48352ScaelIf x(z) and y(z) are
222*48352Scael.Em any
223*48352Scaelfunctions analytic (expandable
22424371Smiriamin power series) in z around z = 0, and if there
22524371Smiriamx(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
226*48352Scael.Ed
227*48352Scael.It
22824371SmiriamIf 0**0 = 1, then
22924371Smiriam.if n \
23024371Smiriaminfinity**0 = 1/0**0 = 1 too; and
23124371Smiriam.if t \
23224371Smiriam\(if**0 = 1/0**0 = 1 too; and
23324371Smiriamthen \*(nn**0 = 1 too because x**0 = 1 for all finite
23428810Skjdand infinite x, i.e., independently of x.
235*48352Scael.El
236*48352Scael.Sh SEE ALSO
237*48352Scael.Xr math 3 ,
238*48352Scael.Xr infnan 3
239*48352Scael.Sh AUTHOR
24023565SmiriamKwok\-Choi Ng, W. Kahan
241*48352Scael.Sh HISTORY
242*48352ScaelA
243*48352Scael.Fn exp ,
244*48352Scael.Fn log
245*48352Scaeland
246*48352Scael.Fn pow
247*48352Scaelfunction
248*48352Scaelappeared in
249*48352Scael.At v6 .
250*48352ScaelA
251*48352Scael.Fn log10
252*48352Scaelfunction
253*48352Scaelappeared in
254*48352Scael.At v7 .
255*48352ScaelThe
256*48352Scael.Fn log1p
257*48352Scaeland
258*48352Scael.Fn expm1
259*48352Scaelfunctions appeared in
260*48352Scael.Bx 4.3 .
261