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