StrictMath log() Method In Java
The Java.lang.StrictMath.log() is an inbuilt method of StrictMath class which is used to calculate the natural logarithm i.e., log with base e, of a given double value. It gives rise to three special results:
- It returns a positive infinity when the argument is positive infinity.
- It returns NaN when the argument is NaN or less than zero.
- The result is negative infinity when the argument is positive zero or negative zero.
Syntax:
public static double log(double num)
Parameters: The method accepts one parameter num of double type whose logarithmic value is to be found.
Return Value: The method returns the value of natural logarithm of num.
Examples :
Input: num = 5.0 Output: 1.6094379124341003 Input: num = 10.0 Output: 2.302585092994046
Below programs illustrate the Java.lang.StrictMath.log() Method:
Program 1:
// Java praogram to illustrate the // Java.lang.StrictMath.log() Method import java.lang.*; public class Geeks { public static void main(String[] args) { double num1 = 10 , num2 = 25.2 ; // It returns natural logarithm(base e) double log_Value = StrictMath.log(num1); System.out.print("Log value of " + num1 + " = " ); System.out.println(log_Value); log_Value = StrictMath.log(num2); System.out.print("Log value of " + num2 + " = " ); System.out.println(log_Value); } } |
Log value of 10.0 = 2.302585092994046 Log value of 25.2 = 3.2268439945173775
Program 2:
// Java praogram to illustrate the // Java.lang.StrictMath.log() Method import java.lang.*; public class Geeks { public static void main(String[] args) { double num1 = 0 , num2 = (1.0/0.0) , num3 = 1; // It returns natural logarithm(base e) double log_Value = StrictMath.log(num1); System.out.print("Log value of " + num1 + " = " ); System.out.println(log_Value); log_Value = StrictMath.log(num2); System.out.print("Log value of " + num2 + " = " ); System.out.println(log_Value); log_Value = StrictMath.log(num3); System.out.print("Log value of " + num3 + " = " ); System.out.println(log_Value); } } |
Log value of 0.0 = -Infinity Log value of Infinity = Infinity Log value of 1.0 = 0.0
Recommended Posts:
- StrictMath pow() Method in Java
- StrictMath tan() Method in Java
- StrictMath exp() Method in Java
- StrictMath sin() Method in Java
- StrictMath sinh() Method in Java
- StrictMath tanh() Method in Java
- StrictMath ulp() Method In Java with Examples
- StrictMath fma() method in Java with Examples
- StrictMath toDegrees() Method in Java
- StrictMath toRadians() Method in Java
- StrictMath log10() Method in Java
- StrictMath nextUp() Method in Java
- StrictMath signum() Method in Java
- StrictMath sqrt() Method in Java
- StrictMath getExponent() Method In Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



