Java Reference
In-Depth Information
Rounding Toward Negative Infinity
In this rounding mode, numbers are rounded to a value closer to the negative infinity. Some examples of rounding
towards negative infinity are shown in Table 3-16 .
Table 3-16. Examples of Rounding Towards Negative Infinity
Original Number
Available Number of Binary Points
Rounded Number
1.1101
2
1.11
-0.1011
2
-0.11
0.1010
2
0.10
0.0011
2
0.00
Rounding Toward Nearest
In this rounding mode, the rounded result is the nearest representable floating-point number. In case of a tie, that is,
if there are two representable floating-point numbers that are equally near to the original number, the result is the
one that has its least significant bit as zero. In other words, in case of a tie, the rounded result is the even number.
The system, which implements IEEE floating-point standards, has this mode as the default rounding mode. The IEEE
standard states that the system should also allow users to select one of the other three rounding modes. Java uses this
mode as the default rounding mode for floating-point numbers. Java does not allow users (that is, programmers) to
select any other rounding modes. Some examples of rounding towards nearest are shown in Table 3-17 .
Table 3-17. Examples of Rounding Towards Nearest
Original Number
Available Number of Binary Points
Rounded Number
1.1101
2
1.11
-0.1011
2
-0.11
0.1010
2
0.10
0.0011
2
0.01
IEEE Floating-Point Exceptions
The IEEE floating-point standard defines several exceptions that occur when the result of a floating-point operation
is unacceptable. Exceptions can be ignored, in which case some default action is taken, such as returning a special
value. When trapping is enabled for an exception, an error is signaled whenever that exception occurs. Floating-point
operations can lead to any of the following five types of floating point exceptions:
Division by zero exception
Invalid operation exception
Overflow exception
Underflow exception
Inexact exception
 
Search WWH ::




Custom Search