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