HP-UX Floating-Point Guide
54 Chapter 2
Floating-Point Principles and the IEEE Standard for Binary Floating-Point Arithmetic
Exception Conditions
produces an inexact result condition. Because most floating-point
operations produce rounded (that is, inexact) results most of the time,
the inexact result exception is not usually considered to be an error.
The IEEE standard requires that for the basic operations, the result
must always be rounded to the nearest representable value (unless the
rounding mode has been changed; see “IEEE Rounding Modes” on
page 54). So, while the result of dividing 1 by 3 is not precisely 1/3, it is
precisely repeatable, portable, and standard.
An inexact result condition is always raised along with an overflow
condition, and is also raised with an underflow condition. The overflow or
underflow is always raised first. These are the only situations where
more than one exception is raised by the same operation.
Conversions Between Decimal and Binary
Floating-Point Format
Inexactness can occur when the system attempts to convert between
decimal representations and binary floating-point representations. This
can occur, for example, during a C language scanf or printf call.
An inexact conversion from binary to decimal can occur if the format of
the decimal representation does not contain enough room to represent
the floating-point value—for example, if the format specification in a
printf call is %7.5f, but the value being printed requires more than 5
decimal places.
An inexact conversion from decimal to binary can occur because the
IEEE floating-point format cannot represent all decimal values. For
instance, the IEEE format cannot represent the decimal value 0.1
exactly, because 0.1 cannot be represented by a finite sum of powers of 2.
For more information and examples, see “Conversions Between Binary
and Decimal” on page 76.
IEEE Rounding Modes
Choosing the most appropriate representable value through rounding is
not always straightforward. Whether the system rounds to the lower or
higher of two representable values depends upon the rounding mode
(algorithm for rounding values) the user selects. The available choices
include an IEEE standard default rounding mode as well as three
alternate modes.