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

  1. 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.

  2. Handle negative values correctly:

    julia> log1p(-0.5)
    ERROR: DomainError with -0.5: NaN result for non-NaN input.

    The log1p function throws a DomainError if the input value is less than -1.

  3. 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 of log1p that is typically faster and more accurate. You can use it by importing the module and prefixing the function with JuliaLibm..

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.

*Required Field
Details

Checking you are not a robot: