xref: /openbsd-src/lib/libm/man/exp.3 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: exp.3,v 1.20 2008/12/12 00:10:26 martynas Exp $
2.\"
3.\" Copyright (c) 1985, 1991 Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
31.\"
32.Dd $Mdocdate: December 12 2008 $
33.Dt EXP 3
34.Os
35.Sh NAME
36.Nm exp ,
37.Nm expf ,
38.Nm exp2 ,
39.Nm exp2f ,
40.Nm exp2l ,
41.Nm expm1 ,
42.Nm expm1f ,
43.Nm log ,
44.Nm logf ,
45.Nm log10 ,
46.Nm log10f ,
47.Nm log1p ,
48.Nm log1pf ,
49.Nm pow ,
50.Nm powf
51.Nd exponential, logarithm, power functions
52.Sh SYNOPSIS
53.Fd #include <math.h>
54.Ft double
55.Fn exp "double x"
56.Ft float
57.Fn expf "float x"
58.Ft double
59.Fn exp2 "double x"
60.Ft float
61.Fn exp2f "float x"
62.Ft long double
63.Fn exp2l "long double 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
87function computes the base
88.Ms e
89exponential value of the given argument
90.Fa x .
91The
92.Fn expf
93function is a single precision version of
94.Fn exp .
95.Pp
96The
97.Fn exp2
98function computes the base 2 exponential of the given argument
99.Fa x .
100The
101.Fn exp2f
102function is a single precision version of
103.Fn exp2 .
104The
105.Fn exp2l
106function is an extended precision version of
107.Fn exp2 .
108.Pp
109The
110.Fn expm1
111function computes the value exp(x)\-1 accurately even for tiny argument
112.Fa x .
113The
114.Fn expm1f
115function is a single precision version of
116.Fn expm1 .
117.Pp
118The
119.Fn log
120function computes the value of the natural logarithm of argument
121.Fa x .
122The
123.Fn logf
124function is a single precision version of
125.Fn log .
126.Pp
127The
128.Fn log10
129function computes the value of the logarithm of argument
130.Fa x
131to base 10.
132The
133.Fn log10f
134function is a single precision version of
135.Fn log10 .
136.Pp
137The
138.Fn log1p
139function computes
140the value of log(1+x) accurately even for tiny argument
141.Fa x .
142The
143.Fn log1pf
144function is a single precision version of
145.Fn log1p .
146.Pp
147The
148.Fn pow
149function computes the value of
150.Ar x
151to the exponent
152.Ar y .
153The
154.Fn powf
155function is a single precision version of
156.Fn pow .
157.Sh RETURN VALUES
158These functions will return the appropriate computation unless an error
159occurs or an argument is out of range.
160The functions
161.Fn exp ,
162.Fn expm1
163and
164.Fn pow
165detect if the computed value will overflow,
166set the global variable
167.Va errno
168to
169.Er ERANGE
170and cause a reserved operand fault on a
171.Tn VAX
172or
173.Tn Tahoe .
174The function
175.Fn pow x y
176checks to see if
177.Fa x
178< 0 and
179.Fa y
180is not an integer, in the event this is true,
181the global variable
182.Va errno
183is set to
184.Er EDOM
185and on the
186.Tn VAX
187and
188.Tn Tahoe
189generate a reserved operand fault.
190On a
191.Tn VAX
192and
193.Tn Tahoe ,
194.Va errno
195is set to
196.Er EDOM
197and the reserved operand is returned
198by log unless
199.Fa x
200> 0, by
201.Fn log1p
202unless
203.Fa x
204> \-1.
205.Sh ERRORS (due to Roundoff etc.)
206exp(x), log(x), expm1(x) and log1p(x) are accurate to within
207an
208.Em ulp ,
209and log10(x) to within about 2
210.Em ulps ;
211an
212.Em ulp
213is one
214.Em Unit
215in the
216.Em Last
217.Em Place .
218The error in
219.Fn pow x y
220is below about 2
221.Em ulps
222when its
223magnitude is moderate, but increases as
224.Fn pow x y
225approaches
226the over/underflow thresholds until almost as many bits could be
227lost as are occupied by the floating\-point format's exponent
228field; that is 8 bits for
229.Tn "VAX D"
230and 11 bits for IEEE 754 Double.
231No such drastic loss has been exposed by testing; the worst
232errors observed have been below 20
233.Em ulps
234for
235.Tn "VAX D" ,
236300
237.Em ulps
238for
239.Tn IEEE
240754 Double.
241Moderate values of
242.Fn pow
243are accurate enough that
244.Fn pow integer integer
245is exact until it is bigger than 2**56 on a
246.Tn VAX ,
2472**53 for
248.Tn IEEE
249754.
250.Sh NOTES
251The functions exp(x)\-1 and log(1+x) are called
252expm1 and logp1 in
253.Tn BASIC
254on the Hewlett\-Packard
255.Tn HP Ns \-71B
256and
257.Tn APPLE
258Macintosh,
259.Tn EXP1
260and
261.Tn LN1
262in Pascal, exp1 and log1 in C
263on
264.Tn APPLE
265Macintoshes, where they have been provided to make
266sure financial calculations of ((1+x)**n\-1)/x, namely
267expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
268They also provide accurate inverse hyperbolic functions.
269.Pp
270The function
271.Fn pow x 0
272returns x**0 = 1 for all x including x = 0,
273.if n \
274Infinity
275.if t \
276\(if
277(not found on a
278.Tn VAX ) ,
279and
280.Em NaN
281(the reserved
282operand on a
283.Tn VAX ) .
284Previous implementations of pow may
285have defined x**0 to be undefined in some or all of these cases.
286Here are reasons for returning x**0 = 1 always:
287.Bl -enum -width indent
288.It
289Any program that already tests whether x is zero (or
290infinite or \*(Na) before computing x**0 cannot care
291whether 0**0 = 1 or not.
292Any program that depends upon 0**0 to be invalid is dubious anyway since that
293expression's meaning and, if invalid, its consequences
294vary from one computer system to another.
295.It
296Some Algebra texts (e.g., Sigler's) define x**0 = 1 for
297all x, including x = 0.
298This is compatible with the convention that accepts a[0]
299as the value of polynomial
300.Bd -literal -offset indent
301p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
302.Ed
303.Pp
304at x = 0 rather than reject a[0]\(**0**0 as invalid.
305.It
306Analysts will accept 0**0 = 1 despite that x**y can
307approach anything or nothing as x and y approach 0
308independently.
309The reason for setting 0**0 = 1 anyway is this:
310.Bd -filled -offset indent
311If x(z) and y(z) are
312.Em any
313functions analytic (expandable
314in power series) in z around z = 0, and if there
315x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
316.Ed
317.It
318If 0**0 = 1, then
319.if n \
320infinity**0 = 1/0**0 = 1 too; and
321.if t \
322\(if**0 = 1/0**0 = 1 too; and
323then \*(Na**0 = 1 too because x**0 = 1 for all finite
324and infinite x, i.e., independently of x.
325.El
326.Sh SEE ALSO
327.Xr infnan 3 ,
328.Xr math 3
329.Sh HISTORY
330A
331.Fn exp ,
332.Fn log
333and
334.Fn pow
335functions
336appeared in
337.At v6 .
338A
339.Fn log10
340function
341appeared in
342.At v7 .
343The
344.Fn log1p
345and
346.Fn expm1
347functions appeared in
348.Bx 4.3 .
349