Open In App

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: 

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 program 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 program 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

 


Article Tags :