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:
- 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 Double.doubleToRawLongBits() method:
Program 1:
Java
import java.lang.*;
class Gfg1 {
public static void main(String args[])
{
double val = 1 .5d;
long answer = Double.doubleToRawLongBits(val);
System.out.println(val + " in raw long bits: "
+ answer);
}
}
|
Output:
1.5 in raw long bits: 4609434218613702656
Program 2:
Java
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;
long answer = Double.doubleToRawLongBits(val);
System.out.println(val + " in raw long bits: "
+ answer);
answer = Double.doubleToRawLongBits(val1);
System.out.println(val1 + " in raw long bits: "
+ answer);
answer = Double.doubleToRawLongBits(val2);
System.out.println(val2 + " in raw long bits: "
+ answer);
}
}
|
Output:
Infinity in raw long bits: 9218868437227405312
-Infinity in raw long bits: -4503599627370496
NaN in raw long bits: 9221120237041090560
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#doubleToRawLongBits(double)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
19 Nov, 2020
Like Article
Save Article