Skip to contents
loading...

ln() computes natural logarithm, lg() computes base 10 logarithm, and lb() computes binary (base 2) logarithm.

ln1p() and lg1p() computes ln(x + 1) and lg(x + 1) accurately also for |x| << 1.

E is the Euler constant and is equal to exp(1).

Usage

ln(x)

lg(x)

lb(x)

ln1p(x)

lg1p(x)

E

Format

An object of class numeric of length 1.

Arguments

x

A numeric or complex vector.

Details

Those functions are synonyms of log(), log10(), log2(), log1p() for those who prefer the shorter notation. Beginners sometimes make confusion between log() and log10(). Using ln() for natural logarithms instead of log() eliminates this confusion. E is provided for convenience as exp(1), although the use of exp() is usually familiar enough to everyone.

See also

Examples

ln(exp(3))              # Same as log(exp(3))
#> [1] 3
lg(10^3)                # Same as log10(10^3)
#> [1] 3
lb(1:3)                 # Wrapper for log2()
#> [1] 0.000000 1.000000 1.584963

ln1p(c(0, 1, 10, 100))  # Wrapper for log1p()
#> [1] 0.0000000 0.6931472 2.3978953 4.6151205
lg1p(c(0, 1, 10, 100))  # log10(x + 1), but optimized for x << 1
#> [1] 0.000000 0.301030 1.041393 2.004321

E^4                     # Similar to exp(4), but different calculation!
#> [1] 54.59815