Double doubleToRawLongBits() method in Java with examples (original) (raw)

Last Updated : 11 Jul, 2025

The doubleToRawLongBits() method of Java Double class is a built-in function in java that returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout preserving Not-a-Number (NaN) values.

Syntax:

public static long doubleToRawLongBits(double val)

Parameter: The method accepts only one parameter val which specifies a double precision floating-point number.

Return Values: The function returns the bits that represent the floating-point number. Below are the special cases:

Below programs illustrates the use of Double.doubleToRawLongBits() method:

Program 1:

Java `

// Java program to demonstrate // Double.doubleToRawLongBits() method

import java.lang.*;

class Gfg1 {

public static void main(String args[])
{

    double val = 1.5d;

    // function call
    long answer = Double.doubleToRawLongBits(val);

    // print
    System.out.println(val + " in raw long bits: "
                       + answer);
}

}

`

Output:

1.5 in raw long bits: 4609434218613702656

Program 2:

Java `

// Java program to demonstrate // Double.doubleToRawLongBits() method

import java.lang.*;

class Gfg1 {

public static void main(String args[])
{

    double val = Double.POSITIVE_INFINITY;
    double val1 = Double.NEGATIVE_INFINITY;
    double val2 = Double.NaN;

    // function call
    long answer = Double.doubleToRawLongBits(val);

    // print
    System.out.println(val + " in raw long bits: "
                       + answer);

    // function call
    answer = Double.doubleToRawLongBits(val1);

    // print
    System.out.println(val1 + " in raw long bits: "
                       + answer);

    // function call
    answer = Double.doubleToRawLongBits(val2);

    // print
    System.out.println(val2 + " in raw long bits: "
                       + answer);
}

}

`