.log1p()
Published Oct 31, 2022Updated Nov 12, 2022
Contribute to Docs
The Math.log1p()
method returns the natural logarithm of a number plus 1.
Syntax
Math.log1p(a);
- If
a
is a positive number, the return value is adouble
. - If
a
isNaN
or less than -1, the return value isNaN
. - If
a
is -1, the return value is negative infinity - If
a
is positive infinity, the return value is positive infinity. - If
a
is positive or negative zero, the return value is positive or negative zero.
Example
The following example demonstrates using the .log1p()
method to find natural logs:
// Main.javapublic class Main {public static void main(String args[]) {double a = 23;double b = -42;double c = 0;double d = -0;System.out.println("The result of log1p(" + a + ") is: " + Math.log1p(a));System.out.println("The result of log1p(" + b + ") is: " + Math.log1p(b));System.out.println("The result of log1p(" + c + ") is: " + Math.log1p(c));System.out.println("The result of log1p(" + d + ") is: " + Math.log1p(d));}}
This will produce the following output:
The result of log1p(23.0) is: 3.1780538303479458The result of log1p(-42.0) is: NaNThe result of log1p(0.0) is: 0.0The result of log1p(0.0) is: 0.0
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours