Important: The information in this document is obsolete and should not be used for new development.
Converting Floating-Point to Integer Formats
In the PowerPC Numerics environment, the following three types of floating-point to integer conversions are supported either directly by the programming languages or by library implementations:
Although the IEEE standard specifies that conversions from floating-point to integer formats be rounded in the current rounding direction, high-level languages usually define their own methods. For example, the default method of converting from floating-point to integer formats in C is simply to discard the fractional part (truncate). In general, when a language defines the rounding behavior for conversion to or from an integer, PowerPC Numerics languages conform.
- round to integer in current rounding direction (the required conversion, discussed in detail in Chapter 4, "Environmental Controls")
- chop to integer (or round toward zero)
- add half to magnitude and chop
Conversions from floating-point to integer formats raise the invalid floating-point exception flag in any of the following cases:
All floating-point to integer conversions that are in range but inexact (that is, the floating-point value was not an integer) raise the inexact floating-point exception flag, although this is not required by the IEEE standard.
- The floating-point value is out of range for the integer type (for example, an attempt to convert a 64-bit integer value stored in the double data type to a 32-bit integer type).
- The floating-point value is a NaN.
- The floating-point value is an Infinity.
Table 5-1 shows some examples of how floating-point values might be converted to a 32-bit integer format by rounding in the current rounding direction. Note that IEEE rounding in the default direction (to nearest) differs from most common rounding functions on halfway cases.