161285Sbostic.\" Copyright (c) 1985, 1991, 1993 261285Sbostic.\" The Regents of the University of California. All rights reserved. 324694Smckusick.\" 449229Scael.\" %sccs.include.redist.roff% 524694Smckusick.\" 6*66939Sbostic.\" @(#)exp.3 8.2 (Berkeley) 04/19/94 748352Scael.\" 848352Scael.Dd 948352Scael.Dt EXP 3 1048352Scael.Os BSD 4 1148352Scael.Sh NAME 1248352Scael.Nm exp , 1348352Scael.Nm expm1 , 1448352Scael.Nm log , 1548352Scael.Nm log10 , 1648352Scael.Nm log1p , 1748352Scael.Nm pow 1848352Scael.Nd exponential, logarithm, power functions 1948352Scael.Sh SYNOPSIS 2048352Scael.Fd #include <math.h> 2148352Scael.Ft double 2248352Scael.Fn exp "double x" 2348352Scael.Ft double 2448352Scael.Fn expm1 "double x" 2548352Scael.Ft double 2648352Scael.Fn log "double x" 2748352Scael.Ft double 2848352Scael.Fn log10 "double x" 2948352Scael.Ft double 3048352Scael.Fn log1p "double x" 3148352Scael.Ft double 3248352Scael.Fn pow "double x" "double y" 3348352Scael.Sh DESCRIPTION 3448352ScaelThe 3548352Scael.Fn exp 3648352Scaelfunction computes the exponential value of the given argument 3748352Scael.Fa x . 3848352Scael.Pp 3948352ScaelThe 4048352Scael.Fn expm1 4148352Scaelfunction computes the value exp(x)\-1 accurately even for tiny argument 4248352Scael.Fa x . 4348352Scael.Pp 4448352ScaelThe 4548352Scael.Fn log 4648352Scaelfunction computes the value for the natural logarithm of 4748352Scaelthe argument x. 4848352Scael.Pp 4948352ScaelThe 5048352Scael.Fn log10 5148352Scaelfunction computes the value for the logarithm of 5248352Scaelargument 5348352Scael.Fa x 5448352Scaelto base 10. 5548352Scael.Pp 5648352ScaelThe 5748352Scael.Fn log1p 5848352Scaelfunction computes 5948352Scaelthe value of log(1+x) accurately even for tiny argument 6048352Scael.Fa x . 6148352Scael.Pp 6248352ScaelThe 6348352Scael.Fn pow 6448352Scaelcomputes the value 6548352Scaelof 6648352Scael.Ar x 6748352Scaelto the exponent 6848352Scael.Ar y . 6948352Scael.Sh ERROR (due to Roundoff etc.) 7024371Smiriamexp(x), log(x), expm1(x) and log1p(x) are accurate to within 7148352Scaelan 7248352Scael.Em up , 7348352Scaeland log10(x) to within about 2 7448352Scael.Em ups ; 7548352Scaelan 7648352Scael.Em up 7748352Scaelis one 7848352Scael.Em Unit 7948352Scaelin the 8048352Scael.Em Last 8148352Scael.Em Place . 8248352ScaelThe error in 8348352Scael.Fn pow x y 8448352Scaelis below about 2 8548352Scael.Em ups 8648352Scaelwhen its 8748352Scaelmagnitude is moderate, but increases as 8848352Scael.Fn pow x y 8948352Scaelapproaches 9024694Smckusickthe over/underflow thresholds until almost as many bits could be 9124371Smiriamlost as are occupied by the floating\-point format's exponent 9248352Scaelfield; that is 8 bits for 9348352Scael.Tn "VAX D" 9448352Scaeland 11 bits for IEEE 754 Double. 9524694SmckusickNo such drastic loss has been exposed by testing; the worst 9648352Scaelerrors observed have been below 20 9748352Scael.Em ups 9848352Scaelfor 9948352Scael.Tn "VAX D" , 10048352Scael300 10148352Scael.Em ups 10248352Scaelfor 10348352Scael.Tn IEEE 10448352Scael754 Double. 10548352ScaelModerate values of 10648352Scael.Fn pow 10748352Scaelare accurate enough that 10848352Scael.Fn pow integer integer 10948352Scaelis exact until it is bigger than 2**56 on a 11048352Scael.Tn VAX , 11148352Scael2**53 for 11248352Scael.Tn IEEE 11348352Scael754. 11448352Scael.Sh RETURN VALUES 115*66939SbosticThese functions will return the appropriate computation unless an error 11648352Scaeloccurs or an argument is out of range. 11748352ScaelThe functions 11848352Scael.Fn exp , 11948352Scael.Fn expm1 12048352Scaeland 12148352Scael.Fn pow 12248352Scaeldetect if the computed value will overflow, 12348352Scaelset the global variable 12448352Scael.Va errno to 12548352Scael.Er RANGE 12648352Scaeland cause a reserved operand fault on a 12748352Scael.Tn VAX 12848352Scaelor 12948352Scael.Tn Tahoe . 13048352ScaelThe function 13148352Scael.Fn pow x y 13248352Scaelchecks to see if 13348352Scael.Fa x 13448352Scael< 0 and 13548352Scael.Fa y 13648352Scaelis not an integer, in the event this is true, 13748352Scaelthe global variable 13848352Scael.Va errno 13948352Scaelis set to 14048352Scael.Er EDOM 14148352Scaeland on the 14248352Scael.Tn VAX 14348352Scaeland 14448352Scael.Tn Tahoe 14548352Scaelgenerate a reserved operand fault. 14648352ScaelOn a 14748352Scael.Tn VAX 14848352Scaeland 14948352Scael.Tn Tahoe , 15048352Scael.Va errno 15148352Scaelis set to 15248352Scael.Er EDOM 15348352Scaeland the reserved operand is returned 15448352Scaelby log unless 15548352Scael.Fa x 15648352Scael> 0, by 15748352Scael.Fn log1p 15848352Scaelunless 15948352Scael.Fa x 16048352Scael> \-1. 16148352Scael.Sh NOTES 16248352ScaelThe functions exp(x)\-1 and log(1+x) are called 16348352Scaelexpm1 and logp1 in 16448352Scael.Tn BASIC 16548352Scaelon the Hewlett\-Packard 16648352Scael.Tn HP Ns \-71B 16748352Scaeland 16848352Scael.Tn APPLE 16948352ScaelMacintosh, 17048352Scael.Tn EXP1 17148352Scaeland 17248352Scael.Tn LN1 17348352Scaelin Pascal, exp1 and log1 in C 17448352Scaelon 17548352Scael.Tn APPLE 17648352ScaelMacintoshes, where they have been provided to make 17724371Smiriamsure financial calculations of ((1+x)**n\-1)/x, namely 17824371Smiriamexpm1(n\(**log1p(x))/x, will be accurate when x is tiny. 17924371SmiriamThey also provide accurate inverse hyperbolic functions. 18048352Scael.Pp 18148352ScaelThe function 18248352Scael.Fn pow x 0 18348352Scaelreturns x**0 = 1 for all x including x = 0, 18424371Smiriam.if n \ 18524371SmiriamInfinity 18624371Smiriam.if t \ 18723565Smiriam\(if 18848352Scael(not found on a 18948352Scael.Tn VAX ) , 19048352Scaeland 19148352Scael.Em NaN 19248352Scael(the reserved 19348352Scaeloperand on a 19448352Scael.Tn VAX ) . Previous implementations of pow may 19524371Smiriamhave defined x**0 to be undefined in some or all of these 19624371Smiriamcases. Here are reasons for returning x**0 = 1 always: 19748352Scael.Bl -enum -width indent 19848352Scael.It 19924371SmiriamAny program that already tests whether x is zero (or 20050711Scaelinfinite or \*(Na) before computing x**0 cannot care 20124371Smiriamwhether 0**0 = 1 or not. Any program that depends 20224371Smiriamupon 0**0 to be invalid is dubious anyway since that 20324371Smiriamexpression's meaning and, if invalid, its consequences 20424371Smiriamvary from one computer system to another. 20548352Scael.It 20624371SmiriamSome Algebra texts (e.g. Sigler's) define x**0 = 1 for 20724371Smiriamall x, including x = 0. 20824371SmiriamThis is compatible with the convention that accepts a[0] 20924371Smiriamas the value of polynomial 21048352Scael.Bd -literal -offset indent 21124371Smiriamp(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n 21248352Scael.Ed 21348352Scael.Pp 21424371Smiriamat x = 0 rather than reject a[0]\(**0**0 as invalid. 21548352Scael.It 21624371SmiriamAnalysts will accept 0**0 = 1 despite that x**y can 21724371Smiriamapproach anything or nothing as x and y approach 0 21823565Smiriamindependently. 21924371SmiriamThe reason for setting 0**0 = 1 anyway is this: 22048352Scael.Bd -filled -offset indent 22148352ScaelIf x(z) and y(z) are 22248352Scael.Em any 22348352Scaelfunctions analytic (expandable 22424371Smiriamin power series) in z around z = 0, and if there 22524371Smiriamx(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0. 22648352Scael.Ed 22748352Scael.It 22824371SmiriamIf 0**0 = 1, then 22924371Smiriam.if n \ 23024371Smiriaminfinity**0 = 1/0**0 = 1 too; and 23124371Smiriam.if t \ 23224371Smiriam\(if**0 = 1/0**0 = 1 too; and 23350711Scaelthen \*(Na**0 = 1 too because x**0 = 1 for all finite 23428810Skjdand infinite x, i.e., independently of x. 23548352Scael.El 23648352Scael.Sh SEE ALSO 23748352Scael.Xr math 3 , 23848352Scael.Xr infnan 3 23948352Scael.Sh HISTORY 24048352ScaelA 24148352Scael.Fn exp , 24248352Scael.Fn log 24348352Scaeland 24448352Scael.Fn pow 24548352Scaelfunction 24648352Scaelappeared in 24748352Scael.At v6 . 24848352ScaelA 24948352Scael.Fn log10 25048352Scaelfunction 25148352Scaelappeared in 25248352Scael.At v7 . 25348352ScaelThe 25448352Scael.Fn log1p 25548352Scaeland 25648352Scael.Fn expm1 25748352Scaelfunctions appeared in 25848352Scael.Bx 4.3 . 259