xref: /386bsd/usr/src/lib/libm/common_source/exp.3 (revision a2142627)
1.\" Copyright (c) 1985, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)exp.3	6.12 (Berkeley) 7/31/91
33.\"
34.Dd July 31, 1991
35.Dt EXP 3
36.Os BSD 4
37.Sh NAME
38.Nm exp ,
39.Nm expm1 ,
40.Nm log ,
41.Nm log10 ,
42.Nm log1p ,
43.Nm pow
44.Nd exponential, logarithm, power functions
45.Sh SYNOPSIS
46.Fd #include <math.h>
47.Ft double
48.Fn exp "double x"
49.Ft double
50.Fn expm1 "double x"
51.Ft double
52.Fn log "double x"
53.Ft double
54.Fn log10 "double x"
55.Ft double
56.Fn log1p "double x"
57.Ft double
58.Fn pow "double x" "double y"
59.Sh DESCRIPTION
60The
61.Fn exp
62function computes the exponential value of the given argument
63.Fa x .
64.Pp
65The
66.Fn expm1
67function computes the value exp(x)\-1 accurately even for tiny argument
68.Fa x .
69.Pp
70The
71.Fn log
72function computes the value for the natural logarithm of
73the argument x.
74.Pp
75The
76.Fn log10
77function computes the value for the logarithm of
78argument
79.Fa x
80to base 10.
81.Pp
82The
83.Fn log1p
84function computes
85the value of log(1+x) accurately even for tiny argument
86.Fa x .
87.Pp
88The
89.Fn pow
90computes the value
91of
92.Ar x
93to the exponent
94.Ar y .
95.Sh ERROR (due to Roundoff etc.)
96exp(x), log(x), expm1(x) and log1p(x) are accurate to within
97an
98.Em up ,
99and log10(x) to within about 2
100.Em ups ;
101an
102.Em up
103is one
104.Em Unit
105in the
106.Em Last
107.Em Place .
108The error in
109.Fn pow x y
110is below about 2
111.Em ups
112when its
113magnitude is moderate, but increases as
114.Fn pow x y
115approaches
116the over/underflow thresholds until almost as many bits could be
117lost as are occupied by the floating\-point format's exponent
118field; that is 8 bits for
119.Tn "VAX D"
120and 11 bits for IEEE 754 Double.
121No such drastic loss has been exposed by testing; the worst
122errors observed have been below 20
123.Em ups
124for
125.Tn "VAX D" ,
126300
127.Em ups
128for
129.Tn IEEE
130754 Double.
131Moderate values of
132.Fn pow
133are accurate enough that
134.Fn pow integer integer
135is exact until it is bigger than 2**56 on a
136.Tn VAX ,
1372**53 for
138.Tn IEEE
139754.
140.Sh RETURN VALUES
141These functions will return the approprate computation unless an error
142occurs or an argument is out of range.
143The functions
144.Fn exp ,
145.Fn expm1
146and
147.Fn pow
148detect if the computed value will overflow,
149set the global variable
150.Va errno to
151.Er RANGE
152and cause a reserved operand fault on a
153.Tn VAX
154or
155.Tn Tahoe .
156The function
157.Fn pow x y
158checks to see if
159.Fa x
160< 0 and
161.Fa y
162is not an integer, in the event this is true,
163the global variable
164.Va errno
165is set to
166.Er EDOM
167and on the
168.Tn VAX
169and
170.Tn Tahoe
171generate a reserved operand fault.
172On a
173.Tn VAX
174and
175.Tn Tahoe ,
176.Va errno
177is set to
178.Er EDOM
179and the reserved operand is returned
180by log unless
181.Fa x
182> 0, by
183.Fn log1p
184unless
185.Fa x
186> \-1.
187.Sh NOTES
188The functions exp(x)\-1 and log(1+x) are called
189expm1 and logp1 in
190.Tn BASIC
191on the Hewlett\-Packard
192.Tn HP Ns \-71B
193and
194.Tn APPLE
195Macintosh,
196.Tn EXP1
197and
198.Tn LN1
199in Pascal, exp1 and log1 in C
200on
201.Tn APPLE
202Macintoshes, where they have been provided to make
203sure financial calculations of ((1+x)**n\-1)/x, namely
204expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
205They also provide accurate inverse hyperbolic functions.
206.Pp
207The function
208.Fn pow x 0
209returns x**0 = 1 for all x including x = 0,
210.if n \
211Infinity
212.if t \
213\(if
214(not found on a
215.Tn VAX ) ,
216and
217.Em NaN
218(the reserved
219operand on a
220.Tn VAX ) .  Previous implementations of pow may
221have defined x**0 to be undefined in some or all of these
222cases.  Here are reasons for returning x**0 = 1 always:
223.Bl -enum -width indent
224.It
225Any program that already tests whether x is zero (or
226infinite or \*(Na) before computing x**0 cannot care
227whether 0**0 = 1 or not. Any program that depends
228upon 0**0 to be invalid is dubious anyway since that
229expression's meaning and, if invalid, its consequences
230vary from one computer system to another.
231.It
232Some Algebra texts (e.g. Sigler's) define x**0 = 1 for
233all x, including x = 0.
234This is compatible with the convention that accepts a[0]
235as the value of polynomial
236.Bd -literal -offset indent
237p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
238.Ed
239.Pp
240at x = 0 rather than reject a[0]\(**0**0 as invalid.
241.It
242Analysts will accept 0**0 = 1 despite that x**y can
243approach anything or nothing as x and y approach 0
244independently.
245The reason for setting 0**0 = 1 anyway is this:
246.Bd -filled -offset indent
247If x(z) and y(z) are
248.Em any
249functions analytic (expandable
250in power series) in z around z = 0, and if there
251x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
252.Ed
253.It
254If 0**0 = 1, then
255.if n \
256infinity**0 = 1/0**0 = 1 too; and
257.if t \
258\(if**0 = 1/0**0 = 1 too; and
259then \*(Na**0 = 1 too because x**0 = 1 for all finite
260and infinite x, i.e., independently of x.
261.El
262.Sh SEE ALSO
263.Xr math 3 ,
264.Xr infnan 3
265.Sh HISTORY
266A
267.Fn exp ,
268.Fn log
269and
270.Fn pow
271function
272appeared in
273.At v6 .
274A
275.Fn log10
276function
277appeared in
278.At v7 .
279The
280.Fn log1p
281and
282.Fn expm1
283functions appeared in
284.Bx 4.3 .
285