Java Reference
In-Depth Information
Comparison of Float and Double objects behaves differently than float
and double values. Each wrapper class defines a sorting order that treats
0 less than +0, NaNs greater than all values (including +
), and all
NaNs equal to each other.
When converting to a string, NaN values return the string "NaN" , + re-
turns "Infinity" and - returns "-Infinity" . The string-taking construct-
or, and the parse Type method are defined in terms of the valueOf method,
which accepts strings in the following form:
The values "NaN" or "Infinity" with an optional leading + or - char-
acter
A floating-point literal
A hexadecimal floating-point literal
In contrast to the integer wrapper classes, the string is first stripped
of leading and trailing whitespace. If the literal forms contain a trailing
float or double specifier, such as "1.0f" , the specifier is ignored and the
string is converted directly to a value of the requested type.
To let you manipulate the bits inside a floating-point value's represent-
ation, Float provides methods to get the bit pattern as an int , as well as
a way to convert a bit pattern in an int to a float value (according to the
appropriate IEEE 754 floating-point bit layout). The Double class provides
equivalent methods to turn a double value into a long bit pattern and vice
versa:
public static int floatToIntBits(float val)
Returns the bit representation of the float value as an int . All
NaN values are always represented by the same bit pattern.
public static int floatToRawIntBits(float val)
Search WWH ::




Custom Search