ieee_handler(3m) gives an easy way to trap on common exceptions only. These exceptions can seldom be ignored when they occur. The first three (invalid, division, and overflow) are sometimes collectively called common exceptions. IEEE 754 defines five basic types of floating point exceptions: invalid operation, division by zero, overflow, underflow and inexact. If the program has installed a SIGFPE signal handler, the system transfers control to that handler otherwise, the program aborts. If the exception's trap is enabled, the system generates a SIGFPE signal.If the exception's trap is disabled (the default case), the system records the fact that the exception occurred and continues executing the program using the default result specified by IEEE 754 for the excepting operation.(This example is one case of an invalid operation exception.) When such an exception occurs, the system responds in one of two ways: Kahan.)įor example, an exception arises when a program attempts to take the square root of a negative number. (See Handling Arithmetic Exceptions by W. The meanings of atomic and acceptable vary with time and place. Kahan, An arithmetic exception arises when an attempted atomic arithmetic operation has no result that would be acceptable universally. This chapter lists the exceptions defined by IEEE 754 along with their default results and describes the features of the floating point environment that support status flags, trapping, and exception handling. The program can optionally supply a trap handler that handles the exception in an appropriate manner, for example by providing an alternate result for the exceptional operation and resuming execution. The standards also recommend that an implementation provide a means for a program to trap (i.e., interrupt normal control flow) when an exception occurs. To achieve this objective, the standards specify default results for exceptional operations and require that an implementation provide status flags, which can be sensed, set, or cleared by a user, to indicate that exceptions have occurred. The arithmetic system is intended to continue to function on a computation as long as possible, handling unusual situations with reasonable default responses, including setting appropriate flags. to minimize for users the complications arising from exceptional conditions. One objective of these facilities is explained in the IEEE 854 Standard (IEEE 854, page 18). The floating point environment provided by the Sun WorkShop 6 compilers and the Solaris operating environment on SPARC and x86 platforms supports all of the exception handling facilities required by the IEEE standard as well as many of the recommended optional facilities.
#Hjsplit invalid floating point operation how to#
This chapter describes IEEE floating point exceptions and shows how to detect, locate, and handle them. Chapter 4 Exceptions and Exception Handling