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