Open In App

Double doubleToRawLongBits() method in Java with examples

Last Updated : 19 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Java program to demonstrate
// Double.doubleToRawLongBits() method
 
import java.lang.*;
 
class Gfg1 {
 
    public static void main(String args[])
    {
 
        double val = 1.5d;
 
        // function call
        long answer = Double.doubleToRawLongBits(val);
 
        // print
        System.out.println(val + " in raw long bits: "
                           + answer);
    }
}


Output: 

1.5 in raw long bits: 4609434218613702656



 

Program 2: 

Java




// Java program to demonstrate
// Double.doubleToRawLongBits() method
 
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;
 
        // function call
        long answer = Double.doubleToRawLongBits(val);
 
        // print
        System.out.println(val + " in raw long bits: "
                           + answer);
 
        // function call
        answer = Double.doubleToRawLongBits(val1);
 
        // print
        System.out.println(val1 + " in raw long bits: "
                           + answer);
 
        // function call
        answer = Double.doubleToRawLongBits(val2);
 
        // print
        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)
 



Similar Reads

Java Guava | Doubles.indexOf(double[] array, double target) method with Examples
Doubles.indexOf(double[] array, double target) method of Guava's Doubles Class accepts two parameters array and target. If the target exists within the array, the method returns the position of its first occurrence. If the target does not exist within the array, the method returns -1. Syntax: public static int indexOf(double[] array, double target)
3 min read
Java Guava | Doubles.indexOf(double[] array, double[] target) method with Examples
Doubles.indexOf(double[] array, double[] target) method of Guava's Doubles Class accepts two parameters array and target. If the target exists within the array, the method returns the start position of its first occurrence. If the target does not exist within the array, the method returns -1. Syntax: public static int indexOf(double[] array, double
3 min read
Double byteValue() Method in Java with Examples
The java.lang.Double.byteValue() is a built-in method in Java that returns the value of this Double as a byte(by casting to a byte). Basically it used for narrowing primitive conversion of Double type to a byte value. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return Value: This method returns the double
3 min read
Double.compareTo() Method in Java with Examples
The java.lang.Double.compareTo() is a built-in method in java that compares two Double objects numerically. This method returns 0 if this object is equal to the argument object, it returns less than 0 if this object is numerically less than the argument object and a value greater than 0 if this object is numerically greater than the argument object
3 min read
Double.equals() Method in Java with Examples
The java.lang.Double.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. It returns false if both the objects are not same. In all other cases, compareTo method should be prefer
2 min read
Double doubleValue() method in Java with examples
The doubleValue() method of Double class is a built in method to return the value specified by the calling object as double after type casting. Syntax: DoubleObject.doubleValue() Return Value: It return the value of DoubleObject as double. Below programs illustrate doubleValue() method in Java: Program 1: Java Code // Java code to demonstrate // Do
2 min read
Double intValue() method in Java with examples
The intValue() method of Double class is a built in method to return the value specified by the calling object as int after type casting. Syntax: DoubleObject.intValue() Return Value: It return the value of DoubleObject as int. Below programs illustrate intValue() method in Java: Program 1: // Java code to demonstrate // Double intValue() method cl
2 min read
Double shortValue() method in Java with examples
The shortValue() method of Double class is a built in method to return the value specified by the calling object as short after type casting.Syntax: DoubleObject.shortValue() Return Value: It return the value of DoubleObject as short.Below programs illustrate shortValue() method in Java: Program 1: Java Code // Java code to demonstrate // Double sh
2 min read
Double hashCode() method in Java with examples
The hashCode() method of Double class is a built-in method use to return the hashcode value of this Double object. Syntax: DoubleObject.hashCode() Parameters: It takes no parameters. Return Type: It returns an int value. The value returned is (int)(v^(v>>>32)) where v is a long variable equal to Double.doubleToLongBits(this.doubleValue()).
1 min read
Double isInfinite() method in Java with examples
The java.lang.Double.isInfinite() method of Java Double class is a built in method in Java returns true if this Double value or the specified double value is infinitely large in magnitude, false otherwise. Syntax: public boolean isInfinite() or public static boolean isInfinite(double val) Parameters: The function accepts a single parameter val whic
2 min read
Practice Tags :