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


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).

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.
The numerics environment supports five exception flags:

These are discussed in the paragraphs that follow.

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
OperationInvalid condition
Addition or subtractionMagnitude subtraction of Infinities,
for example, (+ ) + ( - )
Multiplication
Division 0/0 or /
Remainderx rem y, where y is 0 or x is infinite
Square rootA negative operand
ConversionSee Chapter 5, "Conversions"
ComparisonWith 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, logb(0) 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.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996