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