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 ofNumbertype, for which we want to find thelog1p().
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
-
Number: It returns the natural log of ( 1 +param). It is of the typeNumber. -
-Infinity: The function returns this if the input parameterparam= -1. -
+Infinity: The function returns this if the input parameterparam=+Infinity. -
NaN: The function returns this if the input parameterparam< -1 orparam=-Infinity.
The
ein 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));