Exponential Functions

DESCRIPTION:

Returns the exponential, logarithm, or square root of the input.

USAGE:

exp(x)
log(x)
logb(x, base=exp(1))
log10(x)
log2(x)
sqrt(x)
log1p(x)
expm1(x)

REQUIRED ARGUMENTS:

x
numeric or complex. Missing values ( NAs) are allowed. log1p and expm1 do not accept complex inputs.

OPTIONAL ARGUMENTS:

base
(positive) numeric or complex base for logarithms.

VALUE:

data transformed by the specified function, with attributes preserved (e.g., a matrix remains a matrix). log computes natural logs. log1p(x) computes log(1+x) but avoids the loss of precision in computing 1+x when x is close to 0. expm1(x) computes exp(x)-1 but is more accurate than the naive expression when x is close to 0.

CLASSES:

This function will be used as the default method for classes that do not inherit a specific method for the function or for the Math group of functions. The result will retain the class and the attributes. If this behavior is not appropriate, the designer of the class should provide a method for the function or for the Math group

DETAILS:

Missing in input means output missing. Numeric arguments must be non-negative for log, logb , log10, log2 , and sqrt, otherwise NA is returned and a warning message is generated; coerce the numbers to complex to avoid this.

The functions exp, log, expm1, and log1p are members of the Math group of generic functions. Because members of this group have only one argument, the logb function replaces the old log function when you need to specify a base for the logarithm. log10 and log2 call logb with base equal to 10 and 2, respectively.

See section 5.1.5 of Becker, Chambers and Wilks for details on domains and branch cuts in the case of complex arguments.

REFERENCES:

Becker, R.A., Chambers, J.M., and Wilks, A.R. (1988). The New S Language Wadsworth and Brooks/Cole, Pacific Grove, CA.

SEE ALSO:

, (for exponentiation).

EXAMPLES:

log2(64)  # base 2 logarithms
logb(100, 10) == log10(100)  # log10 computes the common logarithm
log(-3)  # returns NA
log(as.complex(-3))  # equals log(3) plus pi times i
arc <- seq(0, pi/2, len=50)
exp((1i) * arc)  # part of the unit circle in the complex plane
sqrt(2)
log1p(1e-10) # slightly less than 1e-10
log1p(1e-20) # c. 1e-20, not the 0 that log(1+1e-20) gives
expm1(1e-20) # c. 1e-20, not the 0 that exp(1e-20)-1 gives