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.12 1997/07/14 23:23:50 kleink Exp $ 34.\" 35.Dd July 31, 1991 36.Dt EXP 3 37.Os 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 163to 164.Er ERANGE 165and cause a reserved operand fault on a 166.Tn VAX 167or 168.Tn Tahoe . 169The function 170.Fn pow x y 171checks to see if 172.Fa x 173< 0 and 174.Fa y 175is not an integer, in the event this is true, 176the global variable 177.Va errno 178is set to 179.Er EDOM 180and on the 181.Tn VAX 182and 183.Tn Tahoe 184generate a reserved operand fault. 185On a 186.Tn VAX 187and 188.Tn Tahoe , 189.Va errno 190is set to 191.Er EDOM 192and the reserved operand is returned 193by log unless 194.Fa x 195> 0, by 196.Fn log1p 197unless 198.Fa x 199> \-1. 200.Sh NOTES 201The functions exp(x)\-1 and log(1+x) are called 202expm1 and logp1 in 203.Tn BASIC 204on the Hewlett\-Packard 205.Tn HP Ns \-71B 206and 207.Tn APPLE 208Macintosh, 209.Tn EXP1 210and 211.Tn LN1 212in Pascal, exp1 and log1 in C 213on 214.Tn APPLE 215Macintoshes, where they have been provided to make 216sure financial calculations of ((1+x)**n\-1)/x, namely 217expm1(n\(**log1p(x))/x, will be accurate when x is tiny. 218They also provide accurate inverse hyperbolic functions. 219.Pp 220The function 221.Fn pow x 0 222returns x**0 = 1 for all x including x = 0, 223.if n \ 224Infinity 225.if t \ 226\(if 227(not found on a 228.Tn VAX ) , 229and 230.Em NaN 231(the reserved 232operand on a 233.Tn VAX ) . Previous implementations of pow may 234have defined x**0 to be undefined in some or all of these 235cases. Here are reasons for returning x**0 = 1 always: 236.Bl -enum -width indent 237.It 238Any program that already tests whether x is zero (or 239infinite or \*(Na) before computing x**0 cannot care 240whether 0**0 = 1 or not. Any program that depends 241upon 0**0 to be invalid is dubious anyway since that 242expression's meaning and, if invalid, its consequences 243vary from one computer system to another. 244.It 245Some Algebra texts (e.g. Sigler's) define x**0 = 1 for 246all x, including x = 0. 247This is compatible with the convention that accepts a[0] 248as the value of polynomial 249.Bd -literal -offset indent 250p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n 251.Ed 252.Pp 253at x = 0 rather than reject a[0]\(**0**0 as invalid. 254.It 255Analysts will accept 0**0 = 1 despite that x**y can 256approach anything or nothing as x and y approach 0 257independently. 258The reason for setting 0**0 = 1 anyway is this: 259.Bd -filled -offset indent 260If x(z) and y(z) are 261.Em any 262functions analytic (expandable 263in power series) in z around z = 0, and if there 264x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0. 265.Ed 266.It 267If 0**0 = 1, then 268.if n \ 269infinity**0 = 1/0**0 = 1 too; and 270.if t \ 271\(if**0 = 1/0**0 = 1 too; and 272then \*(Na**0 = 1 too because x**0 = 1 for all finite 273and infinite x, i.e., independently of x. 274.El 275.Sh SEE ALSO 276.Xr math 3 277.Sh STANDARDS 278The 279.Fn exp , 280.Fn log , 281.Fn log10 282and 283.Fn pow 284functions conform to 285.St -ansiC . 286.Sh HISTORY 287A 288.Fn exp , 289.Fn log 290and 291.Fn pow 292functions 293appeared in 294.At v6 . 295A 296.Fn log10 297function 298appeared in 299.At v7 . 300The 301.Fn log1p 302and 303.Fn expm1 304functions appeared in 305.Bx 4.3 . 306