Java Reference
In-Depth Information
Division by Zero Exception
A division by zero exception occurs when a non-zero number is divided by a floating-point zero. If no trap handler is
installed, infinity of appropriate sign is delivered as the result.
Invalid Operation Exception
An invalid operation exception occurs when the operand is invalid for an operation being performed. If no trap
handler is installed, a quiet NaN is delivered as the result. The following are some of the operations that raise an invalid
exception:
Square root of a negative number
Division of zero by zero or of infinity by infinity
Multiplication of zero and infinity
NaN
Any operation on a signaling
Subtracting infinity from infinity
NaN is compared with the > or < relational operators
When a quiet
Overflow Exception
An overflow exception occurs when the result of a floating-point operation is too large in magnitude to fit in the
intended destination format. For example, when you multiply Float.MAX_VALUE by 2 and try to store the result in a
float variable. If no trap handler is installed, the result to be delivered depends on the rounding mode and the sign of
the intermediate result.
If the rounding mode is rounding toward zero, the result of overflow is the largest finite
number that can be represented in that format. The sign of the result is same as the sign of the
intermediate result.
If the rounding mode is rounding toward positive infinity, the negative overflow results in
the most negative finite number for that format and the positive overflow results in the most
positive finite number for that format.
If the rounding mode is rounding toward negative infinity, the negative overflow results in negative
infinity and the positive overflow results in the most positive finite number for that format.
If the rounding mode is rounding toward nearest, the overflow results in infinity. The sign of
the result is same as the sign of the intermediate result.
However, if trap handler is installed, the result delivered to the trap handler in case of overflow is determined as
follows: the infinitely precise result is divided by 2 t and rounded before delivering it to the trap handler. The value of
t is 192 for single-precision format, 1536 for double-precision format, and 3 x 2 n-1 for extended format, where n is the
number of bits used to represent the exponent.
Underflow Exception
The underflow exception occurs when the result of an operation is too small to be represented as a normalized float in
its format. If trapping is enabled, the floating-point-underflow exception is signaled. Otherwise, the operation results in a
denormalized float or zero. Underflow can be abrupt or gradual. If the result of an operation is less than the minimum
value that can be represented in normalized form in the format, the result could be delivered as zero or a denormalized
 
Search WWH ::




Custom Search