# 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); ` ` `  `} ` `} `

Output:

```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); ` ` `  `} ` `} `

Output:

```Log value of 0.0 = -Infinity
Log value of Infinity = Infinity
Log value of 1.0 = 0.0
```

My Personal Notes arrow_drop_up lets make it a lil simple

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.