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