xref: /original-bsd/lib/libm/common_source/exp.3 (revision 4ba124f7)
1.\" Copyright (c) 1985, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)exp.3	8.2 (Berkeley) 04/19/94
7.\"
8.Dd
9.Dt EXP 3
10.Os BSD 4
11.Sh NAME
12.Nm exp ,
13.Nm expm1 ,
14.Nm log ,
15.Nm log10 ,
16.Nm log1p ,
17.Nm pow
18.Nd exponential, logarithm, power functions
19.Sh SYNOPSIS
20.Fd #include <math.h>
21.Ft double
22.Fn exp "double x"
23.Ft double
24.Fn expm1 "double x"
25.Ft double
26.Fn log "double x"
27.Ft double
28.Fn log10 "double x"
29.Ft double
30.Fn log1p "double x"
31.Ft double
32.Fn pow "double x" "double y"
33.Sh DESCRIPTION
34The
35.Fn exp
36function computes the exponential value of the given argument
37.Fa x .
38.Pp
39The
40.Fn expm1
41function computes the value exp(x)\-1 accurately even for tiny argument
42.Fa x .
43.Pp
44The
45.Fn log
46function computes the value for the natural logarithm of
47the argument x.
48.Pp
49The
50.Fn log10
51function computes the value for the logarithm of
52argument
53.Fa x
54to base 10.
55.Pp
56The
57.Fn log1p
58function computes
59the value of log(1+x) accurately even for tiny argument
60.Fa x .
61.Pp
62The
63.Fn pow
64computes the value
65of
66.Ar x
67to the exponent
68.Ar y .
69.Sh ERROR (due to Roundoff etc.)
70exp(x), log(x), expm1(x) and log1p(x) are accurate to within
71an
72.Em up ,
73and log10(x) to within about 2
74.Em ups ;
75an
76.Em up
77is one
78.Em Unit
79in the
80.Em Last
81.Em Place .
82The error in
83.Fn pow x y
84is below about 2
85.Em ups
86when its
87magnitude is moderate, but increases as
88.Fn pow x y
89approaches
90the over/underflow thresholds until almost as many bits could be
91lost as are occupied by the floating\-point format's exponent
92field; that is 8 bits for
93.Tn "VAX D"
94and 11 bits for IEEE 754 Double.
95No such drastic loss has been exposed by testing; the worst
96errors observed have been below 20
97.Em ups
98for
99.Tn "VAX D" ,
100300
101.Em ups
102for
103.Tn IEEE
104754 Double.
105Moderate values of
106.Fn pow
107are accurate enough that
108.Fn pow integer integer
109is exact until it is bigger than 2**56 on a
110.Tn VAX ,
1112**53 for
112.Tn IEEE
113754.
114.Sh RETURN VALUES
115These functions will return the appropriate computation unless an error
116occurs or an argument is out of range.
117The functions
118.Fn exp ,
119.Fn expm1
120and
121.Fn pow
122detect if the computed value will overflow,
123set the global variable
124.Va errno to
125.Er RANGE
126and cause a reserved operand fault on a
127.Tn VAX
128or
129.Tn Tahoe .
130The function
131.Fn pow x y
132checks to see if
133.Fa x
134< 0 and
135.Fa y
136is not an integer, in the event this is true,
137the global variable
138.Va errno
139is set to
140.Er EDOM
141and on the
142.Tn VAX
143and
144.Tn Tahoe
145generate a reserved operand fault.
146On a
147.Tn VAX
148and
149.Tn Tahoe ,
150.Va errno
151is set to
152.Er EDOM
153and the reserved operand is returned
154by log unless
155.Fa x
156> 0, by
157.Fn log1p
158unless
159.Fa x
160> \-1.
161.Sh NOTES
162The functions exp(x)\-1 and log(1+x) are called
163expm1 and logp1 in
164.Tn BASIC
165on the Hewlett\-Packard
166.Tn HP Ns \-71B
167and
168.Tn APPLE
169Macintosh,
170.Tn EXP1
171and
172.Tn LN1
173in Pascal, exp1 and log1 in C
174on
175.Tn APPLE
176Macintoshes, where they have been provided to make
177sure financial calculations of ((1+x)**n\-1)/x, namely
178expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
179They also provide accurate inverse hyperbolic functions.
180.Pp
181The function
182.Fn pow x 0
183returns x**0 = 1 for all x including x = 0,
184.if n \
185Infinity
186.if t \
187\(if
188(not found on a
189.Tn VAX ) ,
190and
191.Em NaN
192(the reserved
193operand on a
194.Tn VAX ) .  Previous implementations of pow may
195have defined x**0 to be undefined in some or all of these
196cases.  Here are reasons for returning x**0 = 1 always:
197.Bl -enum -width indent
198.It
199Any program that already tests whether x is zero (or
200infinite or \*(Na) before computing x**0 cannot care
201whether 0**0 = 1 or not. Any program that depends
202upon 0**0 to be invalid is dubious anyway since that
203expression's meaning and, if invalid, its consequences
204vary from one computer system to another.
205.It
206Some Algebra texts (e.g. Sigler's) define x**0 = 1 for
207all x, including x = 0.
208This is compatible with the convention that accepts a[0]
209as the value of polynomial
210.Bd -literal -offset indent
211p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
212.Ed
213.Pp
214at x = 0 rather than reject a[0]\(**0**0 as invalid.
215.It
216Analysts will accept 0**0 = 1 despite that x**y can
217approach anything or nothing as x and y approach 0
218independently.
219The reason for setting 0**0 = 1 anyway is this:
220.Bd -filled -offset indent
221If x(z) and y(z) are
222.Em any
223functions analytic (expandable
224in power series) in z around z = 0, and if there
225x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
226.Ed
227.It
228If 0**0 = 1, then
229.if n \
230infinity**0 = 1/0**0 = 1 too; and
231.if t \
232\(if**0 = 1/0**0 = 1 too; and
233then \*(Na**0 = 1 too because x**0 = 1 for all finite
234and infinite x, i.e., independently of x.
235.El
236.Sh SEE ALSO
237.Xr math 3 ,
238.Xr infnan 3
239.Sh HISTORY
240A
241.Fn exp ,
242.Fn log
243and
244.Fn pow
245function
246appeared in
247.At v6 .
248A
249.Fn log10
250function
251appeared in
252.At v7 .
253The
254.Fn log1p
255and
256.Fn expm1
257functions appeared in
258.Bx 4.3 .
259