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