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