Skip to content
Chung Leong edited this page Jan 10, 2022 · 3 revisions

log1p - Natural logarithm of 1 + x

float log1p( float $x )

log1p() computes the natural logarithm of 1 + x. The calculation is done in a way such that the result is accurate even if the value of x is near zero.

Parameters:

x - The number to process. It can be a scalar or an array.

Return Value:

The natural logarithm of 1 + x. If x is an array, the return value will also be an array.

Notes:

On platforms where log1p() is absent from the standard C library (i.e. Windows), log1p() is approximated using a first order Taylor expansion when x is near zero:

if(fabs(x) > 1e-4) {
	return log(1.0 + x);
} else {
	return (-0.5 * x + 1.0) * x;
}

Version

1.0 and above.

Clone this wiki locally