Non-Confidential | PDF version | ARM DUI0475M | ||

| ||||

Home > Floating-point Support > IEEE 754 arithmetic > Exceptions arising from IEEE 754 floating-point arithmetic |

Floating-point arithmetic operations can run into various problems. These are known as exceptions, because they indicate unusual or exceptional situations.

For example, the result computed might be either too big or too small to fit into the format, or there might be no way to calculate the result (as in trying to take the square root of a negative number, or trying to divide zero by zero).

The ARM^{®} floating-point environment can handle an exception by inventing a
plausible result for the operation and returning that result, or by trapping the
exception.

For example, the square root of a negative number can produce a NaN, and trying to compute a value too big to fit in the format can produce infinity. If an exception occurs and is ignored, a flag is set in the floating-point status word to tell you that something went wrong at some time in the past.

When an exception occurs, a piece of code called a trap handler is run. The system provides a default trap handler that prints an error message and terminates the application. However, you can supply your own trap handlers to clean up the exceptional condition in whatever way you choose. Trap handlers can even supply a result to be returned from the operation.

For example, if you had an algorithm where it was convenient to assume that 0 divided by 0 was 1, you could supply a custom trap handler for the Invalid Operation exception to identify that particular case and substitute the answer you required.