The ARM Compiler toolchain does not support floating-point exception trapping for AArch64 targets.

Defined in float.h, this function is provided for compatibility with Microsoft products. It enables you to control exception traps and rounding modes.

The function prototype for _controlfp() is:

unsigned int _controlfp(unsigned int new, unsigned int mask);


This function requires a floating-point model that supports exceptions. In ARM Compiler 6 this is enabled by default, and is disabled by armclang command-line options such as -ffast-math.

_controlfp() also modifies a control word using a mask to isolate the bits to modify. For every bit of mask that is zero, the corresponding control word bit is unchanged. For every bit of mask that is nonzero, the corresponding control word bit is set to the value of the corresponding bit of new. The return value is the previous state of the control word.


This is different behavior to that of __ieee_status() or __fp_status(), where you can toggle a bit by setting a zero in the mask word and a one in the flags word.

Table 3 describes the macros you can use to form the arguments to _controlfp().

Table 3. _controlfp argument macros

_MCW_EMMask containing all exception bits
_EM_INVALIDBit describing the Invalid Operation exception
_EM_ZERODIVIDEBit describing the Divide by Zero exception
_EM_OVERFLOWBit describing the Overflow exception
_EM_UNDERFLOWBit describing the Underflow exception
_EM_INEXACTBit describing the Inexact Result exception
_MCW_RCMask for the rounding mode field
_RC_CHOPRounding mode value describing Round Toward Zero
_RC_UPRounding mode value describing Round Up
_RC_DOWNRounding mode value describing Round Down
_RC_NEARRounding mode value describing Round To Nearest


The 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:

_controlfp(_RC_DOWN, _MCW_RC);

To trap the Invalid Operation exception and untrap all other exceptions:

_controlfp(_EM_INVALID, _MCW_EM);

To untrap the Inexact Result exception:

_controlfp(0, _EM_INEXACT);

Show/hideSee also


ARM C and C++ Libraries and Floating-Point Support User Guide:

Copyright © 2014 ARM. All rights reserved.ARM DUI 0809A