The Math.log1p() function returns the natural logarithm (base e) of 1 + a number, that is
Math.log1p(x)
xIf the value of x is less than -1, the return value is always NaN.
Because log1p() is a static method of Math, you always use it as Math.log1p(), rather than as a method of a Math object you created (Math is not a constructor).
Math.log1p()Math.log1p(1); // 0.6931471805599453 Math.log1p(0); // 0 Math.log1p(-1); // -Infinity Math.log1p(-2); // NaN
This can be emulated with the following function:
Math.log1p = Math.log1p || function(x) {
return Math.log(1 + x);
};
Created by Mozilla Contributors, license: CC-BY-SA 2.5