What is Math.log1p() in JavaScript?

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a log1p() function, which is used to compute the natural log of 1 plus the specified number.

Syntax

Math.log1p(param);

Parameter

  • param: This is the input value of Number type, for which we want to find the log1p().

Number in JavaScript is a 64-bit double-precision value which is the same as double in C# or Java.

Return value

  • Number: It returns the natural log of ( 1 + param ). It is of the type Number.

  • -Infinity: The function returns this if the input parameter param = -1.

  • +Infinity: The function returns this if the input parameter param = +Infinity.

  • NaN: The function returns this if the input parameter param < -1 or param = -Infinity.

The e in natural log is known as the Euler Number, and its value is equal to approximately 2.71828.

Example

console.log("log1p(-2) = " + Math.log1p(-2));
console.log("log1p(-1) = " + Math.log1p(-1));
console.log("log1p(2) = " + Math.log1p(2));
console.log("log1p(20) = " + Math.log1p(20));
console.log("log1p(∞) = " + Math.log1p(Infinity));
console.log("log1p(-∞) = " + Math.log1p(-Infinity));

Free Resources