java.lang.Double doubleToLongBits(double value)
Syntax:
public static long doubleToLongBits(double value)
Java Code Example :
This java example source code demonstrates the use of doubleToLongBits(double value)) method of Double class.
Some takeaways on the doubleToLongBits(double value) method:
- returns a representation of the specified floating-point value according to the IEEE 754 floating-point “double format” bit layout.
- 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
0x7ff8000000000000L.
package com.javatutorialhq.java.examples;
import static java.lang.System.out;
/*
* This example source code demonstrates the use of
* doubleToLongBits(double value) method of Double class
*/
public class DoubleToLongBits {
public static void main(String[] args) {
Double val1 = 100.25;
Double val2 = 0.0/0.0;
Double val3 = 4.0/0;
Double val4 = -val1/0.0;
/*
* test all the possible scenario
* on using the doubleToLongBits 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
100.25 in long bits=4636754883540680704 NaN in long bits=9221120237041090560 Infinity in long bits=9218868437227405312 -Infinity in long bits=-4503599627370496