Home » Java programming language

Java Double class doubleToLongBits() method with example

Double class doubleToLongBits() method: Here, we are going to learn about the doubleToLongBits() method of Double class with its syntax and example.
Submitted by Preeti Jain, on September 21, 2019

Double class doubleToLongBits() method

  • doubleToLongBits() method is available in java.lang package.
  • doubleToLongBits() method follows IEEE 754 double floating-point standards and according to standards, it returns the bits that denote floating-point value.
  • doubleToLongBits() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • doubleToLongBits() method does not throw an exception at the time of representing bits.

Syntax:

    public static long doubleToLongBits(double value);

Parameter(s):

  • double value – This parameter represents the double precision floating point value.

Return value:

The return type of this method is long, it returns the bits that represent the double precision floating-point value.

Note:

  • If we pass positive infinity, it returns the value 0x7ff0000000000000L.
  • If we pass negative infinity, it returns the value 0xfff0000000000000L.
  • If we pass NaN, it returns the value 0x7ff8000000000000L.

Example:

// Java program to demonstrate the example 
// of doubleToLongBits(double value)
// method of Double class

public class DoubleToLongBitsOfDoubleClass {
    public static void main(String[] args) {
        // Variables initialization
        double value1 = 18.20;
        double value2 = 19.20;

        // Display value1,value2 values
        System.out.println("value1: " + value1);
        System.out.println("value2: " + value2);

        // It returns the bits denoted by the double 
        // floating-point argument by calling 
        // Double.doubleToLongBits(value1)

        long result1 = Double.doubleToLongBits(value1);

        // It returns the bits denoted by the double 
        // floating-point argument by calling 
        // Double.doubleToLongBits(value2)
        long result2 = Double.doubleToLongBits(value2);

        // Display result1,result2 values
        System.out.println("Double.doubleToLongBits(value1): " + result1);
        System.out.println("Double.doubleToLongBits(value2): " + result2);
    }
}

Output

value1: 18.2
value2: 19.2
Double.doubleToLongBits(value1): 4625816062258262835
Double.doubleToLongBits(value2): 4626097537234973491





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.