Datasheet
Floating-point Support
ARM DUI 0067D Copyright © 1999-2001 ARM Limited. All rights reserved. 5-17
Then, if the
frob()
function raises Underflow, it is cleared again by
feclearexcept
, and
so no trap occurs when
feupdateenv
is called. However, if
frob()
raises Invalid
Operation, the sticky flag is set when
feupdateenv
is called, and so the trap handler is
invoked.
This mechanism is provided by C9X because C9X specifies no way to change exception
trapping for individual exceptions. A better method is to use
__ieee_status
to disable
the Underflow trap while leaving the Invalid Operation trap enabled. This has the
advantage that the Invalid Operation trap handler is provided with all the information
about the invalid operation (which operation was being performed on what data), and
can invent a result for the operation. Using the C9X method, the Invalid Operation trap
handler is called after the fact, receives no information about the cause of the exception,
and is called too late to provide a substitute result.
5.3.5 ARM extensions to the C9X interface
ARM provides some extensions to the C9X interface, to enable it to do everything that
the ARM floating-point environment is capable of. This includes trapping and
untrapping individual exception types, and also installing custom trap handlers.
The types
fenv_t
and
fexcept_t
are not defined by C9X to be anything in particular.
ARM defines them both to be the same structure type:
typedef struct {
unsigned statusword;
__ieee_handler_t invalid_handler;
__ieee_handler_t divbyzero_handler;
__ieee_handler_t overflow_handler;
__ieee_handler_t underflow_handler;
__ieee_handler_t inexact_handler;
} fenv_t, fexcept_t;
The members of the above structure are:
•
statusword
is the same status variable that the function
__ieee_status
sees, laid
out in the same format (see The __ieee_status function on page 5-8).
• five function pointers giving the address of the trap handler for each exception.
By default each is NULL. This means that if the exception is trapped then the
default exception trap action happens. The default is to cause a
SIGFPE
signal.
Writing custom exception trap handlers
If you want to install a custom exception trap handler, declare it as a function like this: