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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" from: @(#)exp.3 6.12 (Berkeley) 7/31/91 29.\" $NetBSD: exp.3,v 1.21 2003/08/07 16:44:47 agc Exp $ 30.\" 31.Dd July 31, 1991 32.Dt EXP 3 33.Os 34.Sh NAME 35.Nm exp , 36.Nm expf , 37.Nm expm1 , 38.Nm expm1f , 39.Nm log , 40.Nm logf , 41.Nm log10 , 42.Nm log10f , 43.Nm log1p , 44.Nm log1pf , 45.Nm pow , 46.Nm powf 47.Nd exponential, logarithm, power functions 48.Sh LIBRARY 49.Lb libm 50.Sh SYNOPSIS 51.In math.h 52.Ft double 53.Fn exp "double x" 54.Ft float 55.Fn expf "float x" 56.Ft double 57.Fn expm1 "double x" 58.Ft float 59.Fn expm1f "float x" 60.Ft double 61.Fn log "double x" 62.Ft float 63.Fn logf "float x" 64.Ft double 65.Fn log10 "double x" 66.Ft float 67.Fn log10f "float x" 68.Ft double 69.Fn log1p "double x" 70.Ft float 71.Fn log1pf "float x" 72.Ft double 73.Fn pow "double x" "double y" 74.Ft float 75.Fn powf "float x" "float y" 76.Sh DESCRIPTION 77The 78.Fn exp 79function computes the exponential value of the given argument 80.Fa x . 81.Pp 82The 83.Fn expm1 84function computes the value exp(x)\-1 accurately even for tiny argument 85.Fa x . 86.Pp 87The 88.Fn log 89function computes the value of the natural logarithm of argument 90.Fa x . 91.Pp 92The 93.Fn log10 94function computes the value of the logarithm of argument 95.Fa x 96to base 10. 97.Pp 98The 99.Fn log1p 100function computes 101the value of log(1+x) accurately even for tiny argument 102.Fa x . 103.Pp 104The 105.Fn pow 106computes the value 107of 108.Ar x 109to the exponent 110.Ar y . 111.Sh RETURN VALUES 112These functions will return the appropriate computation unless an error 113occurs or an argument is out of range. 114The functions 115.Fn exp , 116.Fn expm1 117and 118.Fn pow 119detect if the computed value will overflow, 120set the global variable 121.Va errno 122to 123.Er ERANGE 124and cause a reserved operand fault on a 125.Tn VAX . 126The function 127.Fn pow x y 128checks to see if 129.Fa x 130\*[Lt] 0 and 131.Fa y 132is not an integer, in the event this is true, 133the global variable 134.Va errno 135is set to 136.Er EDOM 137and on the 138.Tn VAX 139generate a reserved operand fault. 140On a 141.Tn VAX , 142.Va errno 143is set to 144.Er EDOM 145and the reserved operand is returned 146by log unless 147.Fa x 148\*[Gt] 0, by 149.Fn log1p 150unless 151.Fa x 152\*[Gt] \-1. 153.Sh ERRORS 154exp(x), log(x), expm1(x) and log1p(x) are accurate to within 155an 156.Em ulp , 157and log10(x) to within about 2 158.Em ulps ; 159an 160.Em ulp 161is one 162.Em Unit 163in the 164.Em Last 165.Em Place . 166The error in 167.Fn pow x y 168is below about 2 169.Em ulps 170when its 171magnitude is moderate, but increases as 172.Fn pow x y 173approaches 174the over/underflow thresholds until almost as many bits could be 175lost as are occupied by the floating\-point format's exponent 176field; that is 8 bits for 177.Tn "VAX D" 178and 11 bits for IEEE 754 Double. 179No such drastic loss has been exposed by testing; the worst 180errors observed have been below 20 181.Em ulps 182for 183.Tn "VAX D" , 184300 185.Em ulps 186for 187.Tn IEEE 188754 Double. 189Moderate values of 190.Fn pow 191are accurate enough that 192.Fn pow integer integer 193is exact until it is bigger than 2**56 on a 194.Tn VAX , 1952**53 for 196.Tn IEEE 197754. 198.Sh NOTES 199The functions exp(x)\-1 and log(1+x) are called 200expm1 and logp1 in 201.Tn BASIC 202on the Hewlett\-Packard 203.Tn HP Ns \-71B 204and 205.Tn APPLE 206Macintosh, 207.Tn EXP1 208and 209.Tn LN1 210in Pascal, exp1 and log1 in C 211on 212.Tn APPLE 213Macintoshes, where they have been provided to make 214sure financial calculations of ((1+x)**n\-1)/x, namely 215expm1(n\(**log1p(x))/x, will be accurate when x is tiny. 216They also provide accurate inverse hyperbolic functions. 217.Pp 218The function 219.Fn pow x 0 220returns x**0 = 1 for all x including x = 0, 221.if n \ 222Infinity 223.if t \ 224\(if 225(not found on a 226.Tn VAX ) , 227and 228.Em NaN 229(the reserved 230operand on a 231.Tn VAX ) . 232Previous implementations of pow may 233have defined x**0 to be undefined in some or all of these 234cases. 235Here 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. 241Any program that depends 242upon 0**0 to be invalid is dubious anyway since that 243expression's meaning and, if invalid, its consequences 244vary from one computer system to another. 245.It 246Some Algebra texts (e.g. Sigler's) define x**0 = 1 for 247all x, including x = 0. 248This is compatible with the convention that accepts a[0] 249as the value of polynomial 250.Bd -literal -offset indent 251p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n 252.Ed 253.Pp 254at x = 0 rather than reject a[0]\(**0**0 as invalid. 255.It 256Analysts will accept 0**0 = 1 despite that x**y can 257approach anything or nothing as x and y approach 0 258independently. 259The reason for setting 0**0 = 1 anyway is this: 260.Bd -filled -offset indent 261If x(z) and y(z) are 262.Em any 263functions analytic (expandable 264in power series) in z around z = 0, and if there 265x(0) = y(0) = 0, then x(z)**y(z) \(-\*[Gt] 1 as z \(-\*[Gt] 0. 266.Ed 267.It 268If 0**0 = 1, then 269.if n \ 270infinity**0 = 1/0**0 = 1 too; and 271.if t \ 272\(if**0 = 1/0**0 = 1 too; and 273then \*(Na**0 = 1 too because x**0 = 1 for all finite 274and infinite x, i.e., independently of x. 275.El 276.Sh SEE ALSO 277.Xr math 3 278.Sh STANDARDS 279The 280.Fn exp , 281.Fn log , 282.Fn log10 283and 284.Fn pow 285functions conform to 286.St -ansiC . 287.Sh HISTORY 288A 289.Fn exp , 290.Fn log 291and 292.Fn pow 293functions 294appeared in 295.At v6 . 296A 297.Fn log10 298function 299appeared in 300.At v7 . 301The 302.Fn log1p 303and 304.Fn expm1 305functions appeared in 306.Bx 4.3 . 307