xref: /netbsd-src/lib/libm/man/exp.3 (revision 7c7c171d130af9949261bc7dce2150a03c3d239c)
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.\"	$NetBSD: exp.3,v 1.14 1998/02/05 18:52:01 perry Exp $
34.\"
35.Dd July 31, 1991
36.Dt EXP 3
37.Os
38.Sh NAME
39.Nm exp ,
40.Nm expm1 ,
41.Nm log ,
42.Nm log10 ,
43.Nm log1p ,
44.Nm pow
45.Nd exponential, logarithm, power functions
46.Sh LIBRARY
47.Lb libm
48.Sh SYNOPSIS
49.Fd #include <math.h>
50.Ft double
51.Fn exp "double x"
52.Ft float
53.Fn expf "float x"
54.Ft double
55.Fn expm1 "double x"
56.Ft float
57.Fn expm1f "float x"
58.Ft double
59.Fn log "double x"
60.Ft float
61.Fn logf "float x"
62.Ft double
63.Fn log10 "double x"
64.Ft float
65.Fn log10f "float x"
66.Ft double
67.Fn log1p "double x"
68.Ft float
69.Fn log1pf "float x"
70.Ft double
71.Fn pow "double x" "double y"
72.Ft float
73.Fn powf "float x" "float y"
74.Sh DESCRIPTION
75The
76.Fn exp
77function computes the exponential value of the given argument
78.Fa x .
79.Pp
80The
81.Fn expm1
82function computes the value exp(x)\-1 accurately even for tiny argument
83.Fa x .
84.Pp
85The
86.Fn log
87function computes the value of the natural logarithm of argument
88.Fa x.
89.Pp
90The
91.Fn log10
92function computes the value of the logarithm of argument
93.Fa x
94to base 10.
95.Pp
96The
97.Fn log1p
98function computes
99the value of log(1+x) accurately even for tiny argument
100.Fa x .
101.Pp
102The
103.Fn pow
104computes the value
105of
106.Ar x
107to the exponent
108.Ar y .
109.Sh ERROR (due to Roundoff etc.)
110exp(x), log(x), expm1(x) and log1p(x) are accurate to within
111an
112.Em ulp ,
113and log10(x) to within about 2
114.Em ulps ;
115an
116.Em ulp
117is one
118.Em Unit
119in the
120.Em Last
121.Em Place .
122The error in
123.Fn pow x y
124is below about 2
125.Em ulps
126when its
127magnitude is moderate, but increases as
128.Fn pow x y
129approaches
130the over/underflow thresholds until almost as many bits could be
131lost as are occupied by the floating\-point format's exponent
132field; that is 8 bits for
133.Tn "VAX D"
134and 11 bits for IEEE 754 Double.
135No such drastic loss has been exposed by testing; the worst
136errors observed have been below 20
137.Em ulps
138for
139.Tn "VAX D" ,
140300
141.Em ulps
142for
143.Tn IEEE
144754 Double.
145Moderate values of
146.Fn pow
147are accurate enough that
148.Fn pow integer integer
149is exact until it is bigger than 2**56 on a
150.Tn VAX ,
1512**53 for
152.Tn IEEE
153754.
154.Sh RETURN VALUES
155These functions will return the appropriate computation unless an error
156occurs or an argument is out of range.
157The functions
158.Fn exp ,
159.Fn expm1
160and
161.Fn pow
162detect if the computed value will overflow,
163set the global variable
164.Va errno
165to
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.Sh STANDARDS
280The
281.Fn exp ,
282.Fn log ,
283.Fn log10
284and
285.Fn pow
286functions conform to
287.St -ansiC .
288.Sh HISTORY
289A
290.Fn exp ,
291.Fn log
292and
293.Fn pow
294functions
295appeared in
296.At v6 .
297A
298.Fn log10
299function
300appeared in
301.At v7 .
302The
303.Fn log1p
304and
305.Fn expm1
306functions appeared in
307.Bx 4.3 .
308