Compute Natural Logarithm x + 1 in JavaScript

Posted by yhuang
Public (Editable by Users)
JavaScript
None
Edit
console.log(Math.log1p(1));
// expected output: 0.6931471805599453

console.log(Math.log1p(0));
// expected output: 0

console.log(Math.log1p(-1));
// expected output: -Infinity

console.log(Math.log1p(-2));
// expected output: NaN

Math.log1p(1);  // 0.6931471805599453
Math.log1p(0);  // 0
Math.log1p(-1); // -Infinity
Math.log1p(-2); // NaN