Java Reference
In-Depth Information
number. In case of an abrupt underflow, the result is zero. In case of a gradual underflow, the result is a denormalized
number. The IEEE default is gradual underflow (denormalized numbers). Java supports gradual underflow.
Inexact Exception
The inexact exception is signaled if the rounded result of an operation is not identical to the infinitely precise result.
Inexact exceptions are quite common. 1.0/3.0 is an inexact operation. Inexact exceptions also occur when the
operation overflows without an overflow trap.
Java and IEEE Floating-Point Standards
Java follows a subset of the IEEE-754 standard. The following are some of the differences between the IEEE floating-
point standard and their Java implementations:
Java does not signal the IEEE exceptions.
NaN .
Java has no signaling
Java uses the rounding toward nearest mode to round the inexact results. However, Java
rounds towards zero when converting a floating value to an integer. Java does not provide the
user-selectable rounding modes for floating-point computations: up, down, or towards zero.
(2 24 - 2) NaNs for single-precision format and (2 53 - 2) NaNs for double-precision
format. However, Java defines only one NaN for each of these two formats.
IEEE defines
Table 3-18 lists the parameters for different IEEE formats.
Table 3-18. Parameters for the IEEE Formats
Width in
Bits
Exponent
Width in bits
Precision
Maximum
Exponent
Minimum
Exponent
Exponent Bias
32
8
24
127
-126
127
Single-precision
64
11
53
1023
-1022
1023
Double-precision
>= 43
>= 11
>= 32
>= 1023
<= -1022
Unspecified
Single-extended
>= 79
>= 15
>= 64
>= 16383
<= -16382
Unspecified
Double-extended
Little-Endian and Big-Endian
These two terms are related to the direction of bytes in a word within CPU architecture. Computer memory is
referenced by addresses that are positive integers. It is “natural” to store numbers with the least significant byte coming
before the most significant byte in the computer memory. Sometimes computer designers prefer to use a reversed
order version of this representation. The “natural” order, where less significant byte comes before more significant byte
in memory, is called little-endian. Many vendors like IBM, CRAY, and Sun preferred the reverse order that, of course, is
called big-endian. For example, the 32-bit hex value 0x45679812 would be stored in memory as follows:
Address 00 01 02 03
-------------------------------
Little-endian 12 98 67 45
Big-endian 45 67 98 12
 
 
Search WWH ::




Custom Search