Retained method source

Logarithms and Exponentials

Read full sourcePublisherDownload retained originalPlain-text copy
Publisher
R Core Team — R Documentation (base)
Version
Package base version 4.5.0, as identified by the retained R-patched documentation
Relevant passages
Description; Value; Examples

Equal distances represent equal ratios

The dollar axis uses base-10 logarithms: moving one unit to the right multiplies the amount by ten. This makes amounts across a wide range readable together. Zero and negative amounts have no place on this axis and are rejected explicitly. Positive entered amounts remain intact; the view expands to include them. Smoothing takes place in log space, so its shape is not a probability density per dollar. The exact record table remains the reference for the entered amounts.

The description above explains this tool’s implementation. The publisher’s complete retained reading follows.

Source identity and integrity

Complete log help page, including Description, Value, details, methods, examples, references and version footer.

Retained original · 5,559 bytes
f5cae12df31a7735d0916e36bb555dcd8e03a52bd4f39b4abc6b4fcf25319baa

Reading copy · 2,892 bytes
08f1c728e06be0d5512951ab5008015259845f753746c7a5489a253a54d710fa

Full retained text

Text mechanically extracted from the retained publisher source. Use the original or publisher page to inspect mathematical typesetting and layout.

R: Logarithms and Exponentials

log {base}
R Documentation

Logarithms and Exponentials

Description

log computes logarithms, by default natural logarithms,
log10 computes common (i.e., base 10) logarithms, and
log2 computes binary (i.e., base 2) logarithms.
The general form log(x, base) computes logarithms with base
base.

log1p(x) computes \log(1+x) accurately also for
|x| \ll 1.

exp computes the exponential function.

expm1(x) computes \exp(x) - 1 accurately also for
|x| \ll 1.

Usage

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

log1p(x)

exp(x)
expm1(x)

Arguments

x

a numeric or complex vector.

base

a positive or complex number: the base with respect to which
logarithms are computed.  Defaults to e=exp(1).

Details

All except logb are generic functions: methods can be defined
for them individually or via the Math
group generic.

log10 and log2 are only convenience wrappers, but logs
to bases 10 and 2 (whether computed via log or the wrappers)
will be computed more efficiently and accurately where supported by the OS.
Methods can be set for them individually (and otherwise methods for
log will be used).

logb is a wrapper for log for compatibility with S.  If
(S3 or S4) methods are set for log they will be dispatched.
Do not set S4 methods on logb itself.

All except log are primitive functions.

Value

A vector of the same length as x containing the transformed
values.  log(0) gives -Inf, and log(x) for
negative values of x is NaN.  exp(-Inf) is 0.

For complex inputs to the log functions, the value is a complex number
with imaginary part in the range [-\pi, \pi]: which
end of the range is used might be platform-specific.

S4 methods

exp, expm1, log, log10, log2 and
log1p are S4 generic and are members of the
Math group generic.

Note that this means that the S4 generic for log has a
signature with only one argument, x, but that base can
be passed to methods (but will not be used for method selection).  On
the other hand, if you only set a method for the Math group
generic then base argument of log will be ignored for
your class.

Source

log1p and expm1 may be taken from the operating system,
but if not available there then they are based on the Fortran subroutine
dlnrel by W. Fullerton of Los Alamos Scientific Laboratory (see
https://netlib.org/slatec/fnlib/dlnrel.f) and (for small x) a
single Newton step for the solution of log1p(y) = x
respectively.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
The New S Language.
Wadsworth & Brooks/Cole.
(for log, log10 and exp.)

Chambers, J. M. (1998)
Programming with Data.  A Guide to the S Language.
Springer. (for logb.)

See Also

Trig,
sqrt,
Arithmetic.

Examples

log(exp(3))
log10(1e7) # = 7

x <- 10^-(1+2*1:9)
cbind(deparse.level=2, # to get nice column names
      x, log(1+x), log1p(x), exp(x)-1, expm1(x))

[Package base version 4.5.0 Index]