1 .\" $OpenBSD: exp.3,v 1.29 2015/01/15 19:06:31 schwarze Exp $
3 .\" Copyright (c) 1985, 1991 Regents of the University of California.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
30 .\" from: @(#)exp.3 6.12 (Berkeley) 7/31/91
32 .Dd $Mdocdate: January 15 2015 $
60 .Nd exponential, logarithm, power functions
68 .Fn expl "long double x"
74 .Fn exp2l "long double x"
80 .Fn expm1l "long double x"
86 .Fn logl "long double x"
92 .Fn log2l "long double x"
98 .Fn log10l "long double x"
104 .Fn log1pl "long double x"
106 .Fn pow "double x" "double y"
108 .Fn powf "float x" "float y"
110 .Fn powl "long double x" "long double y"
114 function computes the base
116 exponential value of the given argument
120 function is a single precision version of
124 function is an extended precision version of
129 function computes the base 2 exponential of the given argument
133 function is a single precision version of
137 function is an extended precision version of
142 function computes the value exp(x)\-1 accurately even for tiny argument
146 function is a single precision version of
150 function is an extended precision version of
155 function computes the value of the natural logarithm of argument
159 function is a single precision version of
163 function is an extended precision version of
168 function computes the value of the logarithm of argument
173 function is a single precision version of
177 function is an extended precision version of
182 function computes the value of the logarithm of argument
187 function is a single precision version of
191 function is an extended precision version of
197 the value of log(1+x) accurately even for tiny argument
201 function is a single precision version of
205 function is an extended precision version of
210 function computes the value of
216 function is a single precision version of
220 function is an extended precision version of
223 These functions will return the appropriate computation unless an error
224 occurs or an argument is out of range.
230 detect if the computed value will overflow,
231 set the global variable
235 and cause a reserved operand fault on a VAX or Tahoe.
242 is not an integer, in the event this is true,
247 and on the VAX and Tahoe generate a reserved operand fault.
252 and the reserved operand is returned
260 .Sh ERRORS (due to Roundoff etc.)
261 exp(x), log(x), expm1(x) and log1p(x) are accurate to within
264 and log10(x) to within about 2
278 magnitude is moderate, but increases as
281 the over/underflow thresholds until almost as many bits could be
282 lost as are occupied by the floating\-point format's exponent
283 field; that is 8 bits for
285 and 11 bits for IEEE 754 Double.
286 No such drastic loss has been exposed by testing; the worst
287 errors observed have been below 20
296 are accurate enough that
297 .Fn pow integer integer
298 is exact until it is bigger than 2**56 on a VAX,
301 The functions exp(x)\-1 and log(1+x) are called
302 expm1 and logp1 in BASIC on the Hewlett\-Packard HP-71B
303 and APPLE Macintosh, EXP1 and LN1 in Pascal, exp1 and log1 in C
304 on APPLE Macintoshes, where they have been provided to make
305 sure financial calculations of ((1+x)**n\-1)/x, namely
306 expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
307 They also provide accurate inverse hyperbolic functions.
311 returns x**0 = 1 for all x including x = 0,
316 (not found on a VAX),
319 (the reserved operand on a VAX).
320 Previous implementations of
322 may have defined x**0 to be undefined in some or all of these cases.
323 Here are reasons for returning x**0 = 1 always:
324 .Bl -enum -width indent
326 Any program that already tests whether x is zero (or
327 infinite or \*(Na) before computing x**0 cannot care
328 whether 0**0 = 1 or not.
329 Any program that depends upon 0**0 to be invalid is dubious anyway since that
330 expression's meaning and, if invalid, its consequences
331 vary from one computer system to another.
333 Some Algebra texts (e.g., Sigler's) define x**0 = 1 for
334 all x, including x = 0.
335 This is compatible with the convention that accepts a[0]
336 as the value of polynomial
337 .Bd -literal -offset indent
338 p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
341 at x = 0 rather than reject a[0]\(**0**0 as invalid.
343 Analysts will accept 0**0 = 1 despite that x**y can
344 approach anything or nothing as x and y approach 0
346 The reason for setting 0**0 = 1 anyway is this:
347 .Bd -filled -offset indent
350 functions analytic (expandable
351 in power series) in z around z = 0, and if there
352 x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
357 \*(If**0 = 1/0**0 = 1 too; and
359 \(if**0 = 1/0**0 = 1 too; and
360 then \*(Na**0 = 1 too because x**0 = 1 for all finite
361 and infinite x, i.e., independently of x.
371 functions first appeared in