Defined in float.h, the
_controlfp() function is provided for compatibility with Microsoft products. It enables you to control exception traps and rounding modes.
NoteThe ARM® Compiler toolchain does not support floating-point exception trapping for AArch64 targets.
The function prototype for
NoteThis function requires a floating-point model that supports exceptions. In ARM Compiler 6 this is disabled by default, and can be enabled by the armclang command-line option
_controlfp() also modifies a control
word using a mask to isolate the bits to modify. For every bit of
is zero, the corresponding control word bit is unchanged. For every
mask that is nonzero, the corresponding
control word bit is set to the value of the corresponding bit of
The return value is the previous state of the control word.
NoteThis is different behavior to that of
__fp_status(), where you can toggle a bit by setting a zero in the mask word and a one in the flags word.
The following table describes the
macros you can use to form the arguments to
Table 5-1 _controlfp argument macros
||Mask containing all exception bits|
||Bit describing the Invalid Operation exception|
||Bit describing the Divide by Zero exception|
||Bit describing the Overflow exception|
||Bit describing the Underflow exception|
||Bit describing the Inexact Result exception|
||Mask for the rounding mode field|
||Rounding mode value describing Round Toward Zero|
||Rounding mode value describing Round Up|
||Rounding mode value describing Round Down|
||Rounding mode value describing Round To Nearest|
NoteThe values of these macros are not guaranteed to remain the same in future versions of ARM products. To ensure that your code continues to work if the value changes in future releases, use the macro rather than its value.
For example, to set the rounding mode to round down, call:
To trap the Invalid Operation exception and untrap all other exceptions:
To untrap the Inexact Result exception: