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