log1p
log1p(x)
Accurate natural logarithm of 1+x
. Throws DomainError
for Real
arguments less than -1.
There is an experimental variant in the Base.Math.JuliaLibm
module, which is typically faster and more accurate.
Examples
-
Calculate the natural logarithm of 1 plus a number:
julia> log1p(2.5) 1.252762968495368
In this example, we calculate the natural logarithm of 1 plus 2.5.
-
Handle negative values correctly:
julia> log1p(-0.5) ERROR: DomainError with -0.5: NaN result for non-NaN input.
The
log1p
function throws aDomainError
if the input value is less than -1. -
Use the experimental variant for improved performance and accuracy:
julia> using Base.Math.JuliaLibm julia> log1p(3.0) 1.3862943611198906 julia> JuliaLibm.log1p(3.0) 1.3862943611198906
The
Base.Math.JuliaLibm
module provides an experimental variant oflog1p
that is typically faster and more accurate. You can use it by importing the module and prefixing the function withJuliaLibm.
.
Common mistake example:
julia> log1p(-2)
ERROR: DomainError with -2: NaN result for non-NaN input.
In this example, the input value is less than -1, which is not allowed. Make sure to provide valid input within the defined domain to avoid the DomainError
exception.
See Also
abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.