Java.lang Package Classes

Java Double - doubleToRawLongBits() Method



The java.lang.Double.doubleToRawLongBits() method 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. It includes the following important points:

  • If the argument is positive infinity, the result is 0x7ff0000000000000L.
  • If the argument is negative infinity, the result is 0xfff0000000000000L.
  • If the argument is NaN, the result is the long integer representing the actual NaN value. Unlike the doubleToLongBits method, doubleToRawLongBits does not collapse all the bit patterns encoding a NaN to a single "canonical" NaN value.

Syntax

public static long doubleToRawLongBits(double value)

Parameters

value Specify a double precision floating-point number.

Return Value

Returns the bits that represent the floating-point number.

Exception

NA.

Example:

In the example below, the java.lang.Double.doubleToRawLongBits() method returns the bits that represent the given floating-point number.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {

    //creating double values
    double x = 25;
    double y = -25;

    //printing the bit which represents x
    System.out.print("doubleToRawLongBits value of x is: ");
    System.out.println(Double.doubleToRawLongBits(x)); 

    //printing the bit which represents y
    System.out.print("doubleToRawLongBits value of y is: "); 
    System.out.println(Double.doubleToRawLongBits(y));
  }
}

The output of the above code will be:

doubleToRawLongBits value of x is: 4627730092099895296
doubleToRawLongBits value of y is: -4595641944754880512

❮ Java.lang - Double