log1p

 

Description

Compute log(1+x) accurately for small values of x.

Syntax

double log1p( double x )

Parameters

x
[input] independent variable

Return

The natural logarithm of (x + 1)

Examples

EX1

void    log1p_ex1()
{
    double x = 0.0000000000000001;
    double answer = log1p(x);

    printf("log1p(%.30f) = %.30f\n", x, answer); // Result is "log1p(0.000000000000000100000000000000) = 0.000000000000000100000000000000"
}

EX2

void    log1p_ex2()
{
    double x = 0.000000000000001;
    double answer = log1p(x);

    printf("log1p(%.30f) = %.30f\n", x, answer); // Result is "log1p(0.000000000000001000000000000000) = 0.000000000000000999999999999999"
}

Remark

This funciton is used to calculate when x is very close to zero. For this case, log1p(x) is approximately x, whereas log(x + 1) can be zero.

See Also

ln,log10,log

header to Include

origin.h

Reference