EXP(3F) Silicon Graphics EXP(3F) NAME exp, dexp, cexp, zexp - FORTRAN exponential intrinsic function SYNOPSIS real r1, r2 double precision dp1, dp2 complex cx1, cx2 complex*16 cd1, cd2 r2 = exp(r1) dp2 = dexp(dp1) dp2 = exp(dp1) cx2 = cexp(cx1) cx2 = exp(cx1) cd2 = zexp(cd1) cd2 = exp(cd1) DESCRIPTION exp returns the real exponential function ex of its real argument. dexp returns the double-precision exponential function of its double-precision argument. cexp returns the complex exponential function of its complex argument. zexp returns the complex*16 exponential function of its complex*16 argument. The generic function exp becomes a call to dexp, cexp or zexp as required, depending on the type of its argument. SEE ALSO exp(3M). ORIGIN MIPS Computer Systems Page 1 Release 3.10 June 1992 EXP(3M) Silicon Graphics EXP(3M) NAME exp, expm1, log, log10, log1p, pow, fexp, expf, fexpm1, flog, logf, flog10, log10f, flog1p, powf - exponential, logarithm, power SYNOPSIS #include double exp(double x); float fexp(float x); float expf(float x); double expm1(double x); float fexpm1(float x); float expm1f(float x); double log(double x); float flog(float x); float logf(float x); double log10(double x); float flog10(float x); float log10f(float x); double log1p(double x); float flog1p(float x); float log1pf(float x); double pow(double x, double y); float powf(float x, float y); DESCRIPTION The single-precision routines listed above are only available in the standard math library, -lm. The exp family return the exponential function of x, e**x. The expm1 family return exp(x)-1 accurately even for tiny x. The log functions return the natural logaritm of x. The log10 functions return the base 10 logaritm of x. The log1p family return log(1+x) accurately even for tiny x. pow(x,y) and its single-precision counterpart powf(x,y) return x**y. ERROR (due to Roundoff etc.) exp(x), log(x), expm1(x) and log1p(x) are accurate to within an ulp, and log10(x) to within about 2 ulps; an ulp is one Unit in the Last Place. The error in pow(x,y) is below about 2 ulps when its magnitude is moderate, but increases as pow(x,y) approaches the over/underflow thresholds until almost as many bits could Page 1 Release 3.10 June 1992 EXP(3M) Silicon Graphics EXP(3M) be lost as are occupied by the floating-point format's exponent field; 11 bits for double. No such drastic loss has been exposed by testing; the worst errors observed have been below 300 ulps for double. Moderate values of pow are accurate enough that pow(integer,integer) is exact until it is bigger than 2**53 for double. DIAGNOSTICS In the diagnostics below, functions in the standard math library -lm, are referred to as -lm versions, and those in the the BSD math library -lm43, are referred to as -lm43 versions. When NaN is used as an argument, a NaN is returned. The -lm versions, with the exceptions of the log1p and expm1 functions, always return the default Quiet NaN and set errno to EDOM. The -lm43 versions never set errno. The value of HUGE_VAL is IEEE Infinity. The exp functions return HUGE_VAL when the correct value would overflow, and return zero if the correct value would underflow. With the exception of the expm1 functions, the -lm versions set the value of errno to ERANGE for both underflow and overflow. The log tunctions return NaN when x is less than zero, indicating an invalid operation. With the exception of the log1p functions, the -lm versions also set errno to EDOM. When x is zero, the log functions return -HUGE_VAL. With the exception of the log1p functions, the -lm versions set errno to ERANGE. The pow functions return NaN indicating an invalid operation, if x is negative and y is not an integer. The -lm versions also set errno to EDOM. When x is zero and y is negative, the -lm versions return -HUGE_VAL and set errno to EDOM. The -lm43 versions return HUGE_VAL. When both arguments are zero, the pow functions return one. When the correct value for pow would overflow or underflow the pow functions return HUGE_VAL or zero, respectively. The -lm versions set errno to ERANGE. NOTES Pow(x,0) returns x**0 = 1 for all x including x = 0 and Infinity. Previous implementations of pow defined NaN**0 to be 1 as well, but this behavior has been changed to conform to the IEEE standard. Here are reasons for returning x**0 = 1 in all other cases: (1) Any program that already tests whether x is zero (or infinite) before computing x**0 cannot care whether 0**0 = 1 or not. Any program that depends upon 0**0 to be invalid is dubious anyway since that expression's meaning and, if invalid, its consequences vary from one computer system to another. (2) Some Algebra texts (e.g. Sigler's) define x**0 = 1 for all x, including x = 0. This is compatible with the convention that accepts a[0] as the value of polynomial Page 2 Release 3.10 June 1992 EXP(3M) Silicon Graphics EXP(3M) p(x) = a[0]*x**0 + a[1]*x**1 + a[2]*x**2 +...+ a[n]*x**n at x = 0 rather than reject a[0]*0**0 as invalid. (3) Analysts will accept 0**0 = 1 despite that x**y can approach anything or nothing as x and y approach 0 independently. The reason for setting 0**0 = 1 anyway is this: If x(z) and y(z) are any functions analytic (expandable in power series) in z around z = 0, and if there x(0) = y(0) = 0, then x(z)**y(z) -> 1 as z -> 0. (4) If 0**0 = 1, then infinity**0 = 1/0**0 = 1 too; and because x**0 = 1 for all finite and infinite non-NaN x. BUGS It has been observed that the return value of logf may lose precision on arguments greater in magnitude than 2.0 raised to the 125th power (2 ** 125). SEE ALSO math(3M) Page 3 Release 3.10 June 1992 CPLXEXP(3C++) Silicon Graphics CPLXEXP(3C++) NAME exp, log, pow, sqrt - exponential, logarithm, power, square root functions for the C++ complex library SYNOPSIS #include class complex { public: friend complex exp(complex); friend complex log(complex); friend complex pow(double, complex); friend complex pow(complex, int); friend complex pow(complex, double); friend complex pow(complex, complex); friend complex sqrt(complex); }; DESCRIPTION The following math functions are overloaded by the complex library, where: - x, y, and z are of type complex. z = exp(x) Returns ex. z = log(x) Returns the natural logarithm of x. z = pow(x, y) Returns xy. z = sqrt(x) Returns the square root of x, contained in the first or fourth quadrants of the complex plane. SEE ALSO CPLX.INTRO(3C++), cartpol(3C++), cplxerr(3C++), cplxops(3C++), and cplxtrig(3C++). DIAGNOSTICS exp returns (0, 0) when the real part of x is so small, or the imaginary part is so large, as to cause overflow. When the real part is large enough to cause overflow, exp returns (HUGE, HUGE) if the cosine and sine of the imaginary part of x are positive, (HUGE, -HUGE) if the cosine is positive and the sine is not, (-HUGE, HUGE) if the sine is positive and the cosine is not, and (-HUGE, -HUGE) if neither sine nor cosine is positive. In all these cases, errno is set to ERANGE. log returns (-HUGE, 0) and sets errno to EDOM when x is (0, 0). A message indicating SING error is printed on the standard error output. These error-handling procedures may be changed with the function complex_error (cplxerr(3C++)). Page 1 Release 3.10 June 1992