Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 1 - The PowerPC Numerics Environment
Chapter 4 - Environmental Controls


Rounding Direction Modes

The available rounding direction modes are

The rounding direction affects all conversions, except conversions between decimal structures and decimal strings (described in Chapter 5, "Conversions"), and all arithmetic operations except remainder. All operations are calculated without regard to the range and precision of the data type in which the result is to be stored. That is, an operation first produces a result that is infinitely precise, or exact. If the destination data type cannot represent this number exactly, the result is rounded in the direction specified by the rounding mode.

The default rounding direction is to nearest. In this mode, floating-point expressions deliver the value nearest to the exact result that the destination data type can represent. If two representable values are equally close to the exact result, the expression delivers the one whose least significant bit is zero. Hence, halfway cases (for example, 1.5) round to even when the destination is an integer type or when the round-to-integer operation is used. If the magnitude of the exact result is greater than the data type's largest value (by at least one half unit in the last place), then the Infinity with the corresponding sign is delivered.

The other rounding directions are upward, downward, and toward zero. When rounding upward, the result is the representable value (possibly + ) closest to, and not less than, the exact result. When rounding downward, the result is the representable value (possibly - ) closest to, and not greater than, the exact result. When rounding toward zero, the result is the representable value closest to, and not greater in magnitude than, the exact result. Toward-zero rounding truncates a number to an integer (when the destination is an integer type). Table 4-1 shows some values rounded to integers using different rounding modes.
Table 4-1 Examples of rounding to integer in different directions
Floating-point
number
Rounded to nearestRounded toward 0Rounded downwardRounded
upward
 
1.5 2 1 1 2 
2.5 2 2 2 3 
-2.2-2-2-3-2 


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996