Important: The information in this document is obsolete and should not be used for new development.
Exception Flags
Floating-point exceptions are signaled with exception flags. When an application begins, all floating-point exception flags are cleared and the default rounding direction (to nearest) is in effect. This is the default environment. When an exception occurs, the appropriate exception flag is set, but the application continues normal operation. Floating-point exception flags merely indicate that a particular event has occurred; they do not change the flow of control for the application. An application can examine or set individual exception flags and can save and retrieve the entire environment (rounding direction and exception flags).
The numerics environment supports five exception flags:
- Note
- The Exception Manager, described in the book Inside Macintosh: PowerPC System Software, does not report floating-point exceptions in the first version of the system software for PowerPC processor-based Macintosh computers.
These are discussed in the paragraphs that follow.
- invalid operation (often called simply invalid)
- underflow
- overflow
- divide-by-zero
- inexact
Invalid Operation
The invalid exception (or invalid-operation exception) occurs if an operand is invalid for the operation being performed. The result is a quiet NaN for all destination formats (single, double, or double-double). The invalid conditions for the different operations are
Operation Invalid condition Addition or subtraction Magnitude subtraction of Infinities,
for example, (+ ) + ( )Multiplication Division or Remainder x rem y, where y is 0 or x is infinite Square root A negative operand Conversion See Chapter 5, "Conversions" Comparison With predicates involving less than or greater than, but not unordered, when at least one operand is a NaN In addition, any operation on a signaling NaN except the class and sign inquiries and, on some implementations, sign manipulations (absolute value and copysign) produce an invalid exception.
Underflow
The underflow exception occurs when a floating-point result is both tiny and inexact (and therefore is perhaps significantly less accurate than if there were no limit to the exponent range). A result is considered tiny if it must be represented as a denormalized number.Overflow
The overflow exception occurs when the magnitude of a rounded floating-point result is greater than the largest finite number that the floating-point destination data format can represent. (Invalid exceptions, rather than overflow exceptions, flag the production of an out-of-range value for an integer destination type.)Divide-by-Zero
The divide-by-zero exception occurs when a finite, nonzero number is divided by zero. It also occurs, in the more general case, when an operation on finite operands produces an exact infinite result; for example, returns and signals divide-by-zero. (Overflow exceptions, rather than divide-by-zero exceptions, flag the production of an inexact infinite result.)Inexact
The inexact exception occurs if the rounded result of an operation is not identical to the exact (infinitely precise) result. Thus, an inexact exception always occurs when an overflow or underflow occurs. Valid operations on Infinities are always exact and therefore signal no exceptions. Invalid operations on Infinities are described at the beginning of this section.