Compute log(1+x) accurately for small values of x.
double log1p( double x )
The natural logarithm of (x + 1)
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" }
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.
ln,log10,log
origin.h