Java Reference
In-Depth Information
public static double longBitsToDouble(long bits)
Returns the double corresponding to a given bit map. The argument is con-
sidered to be a representation of a floating-point value according to the
IEEE 754 floating-point double precision layout. The special encodings
produce the following results:
1. The value 0x7ff0000000000000L produces a positive infinity.
2. The value 0xfff0000000000000L produces negative infinity.
3. If the argument is any value in the range 0x7ff0000000000001L through
0x7fffffffffffffffL or in the range 0xfff0000000000001L through
0xffffffffffffffffL, the result is NaN.
Programmers note
Contrary to the requirements of IEEE 754, Java NaN values of type
double are lumped together into a single representation. Distinct val-
ues of NaN are only accessible by use of the Double.double-
ToRawLongBits method.
The following program shows unpacking the bit fields of a float-
ing-point number in double format.
// Reference: Chapter 24
// Description:
//
Bit-level unpacking of floating-pioint data
// Requires:
//
Keyin class in current directory
import java.lang.*;
class BitOps
{
public static void main(String[] args)
{
// Definition of bit field masks for double
final long SIGN = 0x8000000000000000L;
final long EXPN = 0x7ff0000000000000L;
final long SGNF = 0x000fffffffffffffL;
final long BIT1 = 0x8000000000000000L;
// Storage for bit fields
long s;
// Sign
long e;
// Exponent field
long m;
// Significand (mantissa) field
String eS;
// For conversions
double num;
long binVal;
Search WWH ::




Custom Search