HP-UX Floating-Point Guide

Chapter 2 55
Floating-Point Principles and the IEEE Standard for Binary Floating-Point Arithmetic
Exception Conditions
NOTE Most applications do not need the alternate rounding modes.
The default rounding mode is round to nearest. The four rounding
modes are:
Round To
Nearest Round to the representable value closest to the true
value. If two representable values are equally close to
the true value, choose the one whose least significant
bit is 0.
Round Toward
+Infinity Always round toward positive infinity (that is, choose
the algebraically greater value).
Round Toward
Infinity Always round toward negative infinity (that is, choose
the algebraically lesser value).
Round Toward
Zero Always round toward zero (that is, choose the
representation with the smaller magnitude).
For most applications, round to nearest is the best rounding mode. In
round-to-nearest mode, the nearest representable value is never more
than 1/2 ULP away from the exact result being rounded, so the error
introduced from one operation by rounding is never more than 1/2 ULP.
For the other rounding modes, the error is less than 1 ULP.
As an example of the size of a 1/2 ULP rounding error, suppose you tried
to measure precisely the distance to the sun (about 93 million miles). An
error of 1/2 ULP in single-precision would put your measurement off by
about 2.5 miles; an error of 1/2 ULP in double-precision would put it off
by about 8 microns; and an error of 1/2 ULP in quad-precision would put
it off by about 10
17
microns, which is about one millionth of the
diameter of a proton.
You can modify the rounding mode on HP 9000 systems by using library
routines in the fenv suite of routines (see Chapter 5).
NOTE We recommend that you use the default rounding mode when your
application calls library routines. Most math library routines (for
example, log, cos, and pow) consist of many IEEE arithmetic
operations, each of which is affected by the current rounding mode.