Double doubleToLongBits() method in Java with examples
The java.lang.Double.doubleToLongBits() 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.
public static long doubleToLongBits(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:
- If the argument is positive infinity, the result is 7ff0000000000000L.
- If the argument is negative infinity, the result is 0xfff0000000000000L.
- If the argument is NaN, the result is 0x7ff8000000000000L.
Below programs illustrates the use of java.lang.Double.doubleToLongBits() method:
1.5 in long bits: 4609434218613702656
Infinity in long bits: 9218868437227405312 -Infinity in long bits: -4503599627370496 NaN in long bits: 9221120237041090560
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.