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