Java Reference
In-Depth Information
Division by zero exception
Thisexceptionoccurswhenthedivisoriszeroandthedividendisnon-zero.
Accordingtothestandardtheresultisencodedasinfinity.Notethattheop-
eration0/0,whichgeneratesaninvalidexception,isnotconsideredadivi-
sionbyzero.
Overflow exception
Table21-2 showstheexponentencodingsintheIEEE754basicsinglefor-
mat,whichrangesfrom-126to+127.Sincethisexponentisbias127,the
maximumabsoluteexponentisthedecimalvalue254(11111110B)andthe
minimumabsoluteexponentisthedecimalvalue1(00000001B).Theexpo-
nentencodingsof0(00000000B)and255(11111111B)arenotusedinrepre-
sentingrealnumbersinthebasicsingleformat.Ananalysisofthevalid
exponentsintheotherformatsconfirmsthattheexponentdigitvalueof
00...00Bandof11...11Barealsonotpartofthelegalrangeassignedforthe
representationofrealnumbers.
Thisapproachisbasedonthefactthatanycomputerrepresentationof
realnumbersisnecessarilylimitedtoacertainrange.Numbersapproach
thelimitsofthisrangeastheybecomeverylargeorverysmall.The over-
flow conditiontakesplacewheneverarealnumberexceedstherepre-
sentablerangebybecomingtoolarge.Inthestandard'sbasicand
extended formats the maximum representable values have an exponent
in the form 11...10B and a significand of 11..11B. With positive real num-
bers, adding the smallest possible value to this encoding generates a num-
ber that exceeds the representable range (overflow).
The standard requires that when an overflow condition is detected, an
exception be signaled and a special encoding be entered as a result of the
operation. There are four possible variations of the actual results, de-
pending on the selected rounding mode, as follows:
1. If round to nearest is selected, the result of an overflow is encoded as an in-
finity with the sign of the intermediate result.
2. If the truncate mode is selected, the result of an overflow is represented
with the format's encoding for the largest representable number.
3. If round to negative infinity is selected, the result of a positive overflow is
represented with the format's encoding for the largest representable value
and a negative overflow with the encoding for - .
4. If round to positive infinity is selected, the result of a negative overflow is
represented with the format's encoding for the smallest representable
value, and a positive overflow with the encoding for + .
Search WWH ::




Custom Search