public static double longBitsToDouble(long bits)

Returns the double value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout.

If the argument is 0x7ff0000000000000L, the result is positive infinity.

If the argument is 0xfff0000000000000L, the result is negative infinity.

If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns. Distinct values of NaN are only distinguishable by use of the Double.doubleToRawLongBits method.

In all other cases, let s, e, and m be three values that can be computed from the argument:

int s = ((bits >> 63) == 0) ? 1 : -1;

int e = (int)((bits >> 52) & 0x7ffL);

long m = (e == 0) ?

(bits & 0xfffffffffffffL) << 1 :

(bits & 0xfffffffffffffL) | 0x10000000000000L;

Then the floating-point result equals the value of the mathematical expression s·m·2e-1075.

Note that this method may not be able to return a double NaN with exactly same bit pattern as the long argument. IEEE 754 distinguishes between two kinds of NaNs, quiet NaNs and signaling NaNs. The differences between the two kinds of NaN are generally not visible in Java. Arithmetic operations on signaling NaNs turn them into quiet NaNs with a different, but often similar, bit pattern. However, on some processors merely copying a signaling NaN also performs that conversion. In particular, copying a signaling NaN to return it to the calling method may perform this conversion. So longBitsToDouble may not be able to return a double with a signaling NaN bit pattern. Consequently, for some long values, doubleToRawLongBits(longBitsToDouble(start)) may not equal start. Moreover, which particular bit patterns represent signaling NaNs is platform dependent; although all NaN bit patterns, quiet or signaling, must be in the NaN range identified above.

Program:

package com.candidjava; public class DoubleLongBitsToDouble { public static void main(String a[]) { Double d = new Double("15.30"); /* returns the double value corresponding to a given bit representation */ System.out.println(Double.longBitsToDouble(6757689)); System.out.println(Double.longBitsToDouble(0x7ff0000000000000L)); System.out.println(Double.longBitsToDouble(0xfff0000000000000L)); } }

Output:

3.338742E-317

Infinity

-Infinity

Description:

This method returns the double floating-point value with the same bit pattern.

Parameters:

bits - any long integer.

Returns:

the double floating-point value with the same bit pattern.

Related Post