It is hard to define exceptions. To quote W. Kahan,
An arithmetic exception arises when an attempted atomic arithmetic operation has no result that would be acceptable universally. The meanings of atomic and acceptable vary with time and place. (See Handling Arithmetic Exceptions by W. Kahan.)
For example, an exception arises when a program attempts to take the square root of a negative number. This example is one case of an invalid operation exception. When such an exception occurs, the system responds in one of two ways:
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.
If the exception's trap is enabled, the system generates a SIGFPE signal. If the program has installed a SIGFPE signal handler, the system transfers control to that handler; otherwise, the program aborts.
IEEE 754 defines five basic types of floating-point exceptions: invalid operation, division by zero, overflow, underflow and inexact. The first three (invalid, division, and overflow) are sometimes collectively called common exceptions. These exceptions can seldom be ignored when they occur. The ieee_handler(3m) man page explains an easy way to trap on common exceptions only. The other two exceptions (underflow and inexact) are seen more often. In fact, most floating-point operations incur the inexact exception. These exceptions can usually, though not always, be safely ignored. Oracle Solaris Studio 12.4 C, C++, and f77 compilers disable all IEEE traps by default. The f95 compiler enables traps for the common exceptions by default. 754-standard conforming can be restored by compiling with f95 –ftrap=none.
Table 4–1 condenses information found in IEEE Standard 754. It describes the five floating-point exceptions and the default response of an IEEE arithmetic environment when these exceptions are raised.
|