1 .\" Copyright (c) 1985, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)exp.3 8.2 (Berkeley) 4/19/94
33 .\" $FreeBSD: src/lib/libm/common_source/exp.3,v 1.5.2.4 2001/08/17 15:43:05 ru Exp $
45 .Nd exponential, logarithm, power functions
61 .Fn pow "double x" "double y"
65 function computes the exponential value of the given argument
70 function computes the value exp(x)\-1 accurately even for tiny argument
75 function computes the value for the natural logarithm of
80 function computes the value for the logarithm of
88 the value of log(1+x) accurately even for tiny argument
98 .Sh ERROR (due to Roundoff etc.)
99 exp(x), log(x), expm1(x) and log1p(x) are accurate to within
102 and log10(x) to within about 2
116 magnitude is moderate, but increases as
119 the over/underflow thresholds until almost as many bits could be
120 lost as are occupied by the floating\-point format's exponent
121 field; that is 8 bits for
123 and 11 bits for IEEE 754 Double.
124 No such drastic loss has been exposed by testing; the worst
125 errors observed have been below 20
136 are accurate enough that
137 .Fn pow integer integer
138 is exact until it is bigger than 2**56 on a
144 These functions will return the appropriate computation unless an error
145 occurs or an argument is out of range.
151 detect if the computed value will overflow,
152 set the global variable
156 and cause a reserved operand fault on a
166 is not an integer, in the event this is true,
175 generate a reserved operand fault.
183 and the reserved operand is returned
192 The functions exp(x)\-1 and log(1+x) are called
195 on the Hewlett\-Packard
203 in Pascal, exp1 and log1 in C
206 Macintoshes, where they have been provided to make
207 sure financial calculations of ((1+x)**n\-1)/x, namely
208 expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
209 They also provide accurate inverse hyperbolic functions.
213 returns x**0 = 1 for all x including x = 0,
225 Previous implementations of pow may
226 have defined x**0 to be undefined in some or all of these
227 cases. Here are reasons for returning x**0 = 1 always:
228 .Bl -enum -width indent
230 Any program that already tests whether x is zero (or
231 infinite or \*(Na) before computing x**0 cannot care
232 whether 0**0 = 1 or not.
233 Any program that depends
234 upon 0**0 to be invalid is dubious anyway since that
235 expression's meaning and, if invalid, its consequences
236 vary from one computer system to another.
238 Some Algebra texts (e.g. Sigler's) define x**0 = 1 for
239 all x, including x = 0.
240 This is compatible with the convention that accepts a[0]
241 as the value of polynomial
242 .Bd -literal -offset indent
243 p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
246 at x = 0 rather than reject a[0]\(**0**0 as invalid.
248 Analysts will accept 0**0 = 1 despite that x**y can
249 approach anything or nothing as x and y approach 0
251 The reason for setting 0**0 = 1 anyway is this:
252 .Bd -ragged -offset indent
255 functions analytic (expandable
256 in power series) in z around z = 0, and if there
257 x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
262 infinity**0 = 1/0**0 = 1 too; and
264 \(if**0 = 1/0**0 = 1 too; and
265 then \*(Na**0 = 1 too because x**0 = 1 for all finite
266 and infinite x, i.e., independently of x.
289 functions appeared in