Home » Java programming language

Java StrictMath log() method with example

StrictMath Class log() method: Here, we are going to learn about the log() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 26, 2019

StrictMath Class log() method

  • log() method is available in java.lang package.
  • log() method is used to return the logarithm of the given (base e) of the given argument in the method.
  • log() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
  • log() method does not throw any exception.

Syntax:

    public static double log(double d);

Parameter(s):

  • double d – represents the double type argument.

Return value:

The return type of this method is double – it returns the logarithm (base e) of the given argument.

Note:

  • If we pass NaN, method returns NaN.
  • If we pass a value which is less than 0, method returns NaN.
  • If we pass an infinity, method returns the infinity.
  • If we pass 0, method returns a negative infinity.

Example:

// Java program to demonstrate the example
// of log(double d) method of StrictMath Class.

public class Log {
    public static void main(String[] args) {
        // variable declarations
        double d1 = 7.0 / 0.0;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 124.68;

        // Display previous value of d1,d2,d3 and d4  
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // Here, we will get (NaN) because we are
        // passing parameter whose value is less than 0(-0.6)
        System.out.println("StrictMath.log(d3): " + StrictMath.log(d3));

        // Here, we will get (infinity) because we are
        // passing parameter whose value is (infinity)
        System.out.println("StrictMath.log(d1): " + StrictMath.log(d1));

        // Here, we will get (-Infinity) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("StrictMath.log(d2): " + StrictMath.log(d2));

        // Here, we will get (e raised to the power of the given argument) 
        // and we are passing parameter 
        // whose value is (1274.68)
        System.out.println("StrictMath.log(d4): " + StrictMath.log(d4));
    }
}

Output

d1: Infinity
d2: 0.0
d3: -0.6
d4: 124.68
StrictMath.log(d3): NaN
StrictMath.log(d1): Infinity
StrictMath.log(d2): -Infinity
StrictMath.log(d4): 4.825750454899136






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.