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