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