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