Datasheet
Floating-point Support
ARM DUI 0067D Copyright © 1999-2001 ARM Limited. All rights reserved. 5-35
5.5.3 Exceptions
Floating-point arithmetic operations can run into various problems. 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). These are known as exceptions, because they
indicate unusual or exceptional situations.
The ARM floating-point environment can handle exceptions in more than one way.
Ignoring exceptions
The system invents a plausible result for the operation and returns that. 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
point in the past.
Trapping exceptions
This means that 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, that can 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,
that spotted that particular case and substituted the answer you wanted.