Java - Double Class doubleTorRawLongBits() Method

Double class doubleTorRawLongBits() method: Here, we are going to learn about the doubleTorRawLongBits() method of Double class with its syntax and example. By Preeti Jain Last updated : March 23, 2024

Double class doubleTorRawLongBits() method

  • doubleTorRawLongBits() method is available in Double class of java.lang package.
  • doubleTorRawLongBits() method follows IEEE 754 double floating-point standards and according to standards, it returns the bits that denote floating-point value along with preserving NaN value.
  • doubleTorRawLongBits() 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.
  • doubleTorRawLongBits() method does not throw an exception at the time of representing bits along with preserving NaN.

Syntax

public static long doubleToRawLongBits(double value);

Parameters

  • 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 actual NaN values (i.e. it does not collapse all the bit encoding a NaN to a "basic" NaN value).

Example

// Java program to demonstrate the example 
// of doubleToRawLongBits(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.doubleToRawLongBits(value1)
        long result1 = Double.doubleToRawLongBits(value1);
        long result2 = Double.doubleToRawLongBits(value2);

        // Display result1,result2 values
        System.out.println("Double.doubleToRawLongBits(value1): " + result1);
        System.out.println("Double.doubleToRawLongBits(value2): " + result2);
        System.out.print("Double.doubleToRawLongBits(NaN): ");
        System.out.println(Double.doubleToRawLongBits(5.0 % 0));
    }
}

Output

value1: 18.2
value2 :19.2
Double.doubleToRawLongBits(value1): 4625816062258262835
Double.doubleToRawLongBits(value2): 4626097537234973491
Double.doubleToRawLongBits(NaN): 9221120237041090560

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.