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