Home » Java programming language

Java Math Class static double log(double d) with example

Java Math Class static double log(double d) method: Here, we are going to learn about the static double log(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 04, 2019

Math Class static double log(double d)

  • This method is available in java.lang package.
  • This method is used to return the logarithm of the given (base e) of the given argument.
  • This is a static method so it is accessible with the class name too.
  • The return type of this method is double, it returns the logarithm (base e) of the given argument.
  • In this method, we pass only one parameter as an argument of double type.
  • This method does not throw any exception.

Syntax:

    public static double log(double d){
    }

Parameter(s): It accepts a double value, whose logarithm to be found.

Return value:

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

Note:

  • If we pass "NaN", it returns "NaN".
  • If we pass less than 0, it returns "NaN".
  • If we pass positive infinity, it returns the same value (positive infinity).
  • If we pass zero (0 or -0), it returns negative infinity.

Java program to demonstrate example of log(double d) method

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

public class LogMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 124.68;

        // displaying values
        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("Math.log(d3): " + Math.log(d3));

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

        // Here , we will get (-Infinity) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("Math.log(d2) :" + Math.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("Math.log(d4): " + Math.log(d4));
    }
}

Output

E:\Programs>javac LogMethod.java

E:\Programs>java LogMethod
d1: Infinity
d2: 0.0
d3: -0.6
d4: 124.68
Math.log(d3): NaN
Math.log(d1):Infinity
Math.log(d2) :-Infinity
Math.log(d4): 4.825750454899136





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




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.