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