java.lang.Double doubleToRawLongBits(double value)


public static long doubleToRawLongBits(double value)

Java Code Example :

This java example source code demonstrates the use of doubleToRawLongBits(double value)) method of Double class.

Some takeaways on the doubleToRawLongBits(double value)  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.
  • 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.

import static java.lang.System.out;

 * This example source code demonstrates the use of  
 * doubleToRawLongBits(double value) method of Double class

public class DoubleToRawLongBits {

	public static void main(String[] args) {

		Double val1 = 1.35;
		Double val2 = 0.0/0.0;
		Double val3 = 4.3/0;
		Double val4 = -val1/0.0;
		 * test all the possible scenario
		 * on using the doubleToRawLongBits method
		out.println(val1 + " in long bits="
				+ Double.doubleToLongBits(val1));
		out.println(val2 + " in long bits="
				+ Double.doubleToLongBits(val2));
		out.println(val3 + " in long bits="
				+ Double.doubleToLongBits(val3));
		out.println(val4 + " in long bits="
				+ Double.doubleToLongBits(val4));		

Sample Output :

Running the above example source code will give the following output

1.35 in long bits=4608758678669597082
NaN in long bits=9221120237041090560
Infinity in long bits=9218868437227405312
-Infinity in long bits=-4503599627370496

Suggested Reading List :

References :