exp(3) BSD Library Functions Manual exp(3)

## NAME

exp,exp2,expm1-- exponential functions

## SYNOPSIS

#include<math.h>floatexpf(floatx);doubleexp(doublex);longdoubleexpl(longdoublex);floatexp2f(floatx);doubleexp2(doublex);longdoubleexp2l(longdoublex);floatexpm1f(floatx);doubleexpm1(doublex);longdoubleexpm1l(longdoublex);float__exp10f(floatx);double__exp10(doublex);

## DESCRIPTION

Theexp() function computes e**x, the base-e exponential ofx. Theexp2() function computes 2**x, the base-2 exponential ofx. The__exp10() function computes 10**x; it is not defined in the C stan- dard, and therefore may not be portable to other platforms. It is pro- vided as a convenience to programmers because it may be computed more efficiently than pow(10,x). Ifxis nearly zero, then the common expressionexp(x) - 1.0 will suffer from catastrophic cancellation and the result will have little or no pre- cision. Theexpm1() function provides an alternative means to do this calculation without the risk of significant loss of precision. If you find yourself using this function, you are likely to also be interested in thelog1p() function. Note that computations numerically equivalent toexp(x) - 1.0 are often hidden in more complicated expressions; some amount of algebraic manipu- lation may be necessary to take advantage of theexpm1() function. Con- sider the following example, abstracted from a developer's actual produc- tion code in a bug report: double z = exp(-x/y)*(x*x/y/y + 2*x/y + 2) - 2 Whenxis small relative toy, this expression is approximately equal to: double z = 2*(exp(-x/y) - 1) and all precision of the result is lost in the computation due to cata- strophic cancellation. The developer was aware that they were losing precision, but didn't know what to do about it. To remedy the situation, we do a little algebra and re-write the expression to take advantage of theexpm1() function: exp(-x/y)*(x*x/y/y + 2*x/y + 2) - 2 = (2*exp(-x/y) - 2) + exp(-x/y)*((x*x)/(y*y) + 2*x/y) This transformation allows the result to be computed to a high degree of accuracy as follows: const double r = x/y; const double emrm1 = expm1(-r); double z = 2.0*emrm1 + (1.0 + emrm1)*(2.0 + r)*r; It is not always easy to spot such opportunities for improvement; if an expression involvingexp() seems to be suffering from an undue loss of accuracy, try a few simple algebraic operations to see if you can iden- tify a factor with the formexp(x) - 1.0, and substituteexpm1(x) in its place.

## SPECIAL VALUES

exp(+-0) andexp2(+-0) return 1.exp(-infinity) andexp2(-infinity) return +0.exp(+infinity) andexp2(+infinity) return +infinity.expm1(+-0) returns +-0.expm1(-infinity) returns -1.expm1(+infinity) returns +infinity. For all these functions, a range error occurs if the magnitude of x is too large.

## VECTOR OPERATIONS

If you need to apply theexp() functions to SIMD vectors or arrays, using the following functions provided by the Accelerate.framework may give significantly better performance:#include<Accelerate/Accelerate.h>vFloatvexpf(vFloatx);vFloatvexpm1f(vFloatx);voidvvexpf(float*y,constfloat*x,constint*n);voidvvexp(double*y,constdouble*x,constint*n);voidvvexpm1f(float*y,constfloat*x,constint*n);voidvvexpm1(double*y,constdouble*x,constint*n);voidvvexp2f(float*y,constfloat*x,constint*n);voidvvexp2(double*y,constdouble*x,constint*n);

## SEE ALSO

log(3),pow(3),math(3)

## STANDARDS

Theexp(),exp2(), andexpm1() functions conform to ISO/IEC 9899:2011. 4th Berkeley Distribution August 16, 2012 4th Berkeley Distribution

Mac OS X 10.9.1 - Generated Tue Jan 7 19:40:23 CST 2014