| |||
| Home > Floating‑point Support > Controlling the floating‑point environment > Microsoft compatibility functions | |||
The following functions are implemented for compatibility
with Microsoft products, to ease porting of floating-point code
to the ARM architecture. They are defined in float.h.
The function _controlfp() enables you
to control exception traps and rounding modes:
unsigned int _controlfp(unsigned int new, unsigned int mask);
This function 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 not quite the same as the behavior 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 4.8 describes
the macros you can use to form the arguments to _controlfp().
Table 4.8. _controlfp argument macros
| Macro | Description |
|---|---|
_MCW_EM | Mask containing all exception bits |
_EM_INVALID | Bit describing the Invalid Operation exception |
_EM_ZERODIVIDE | Bit describing the Divide by Zero exception |
_EM_OVERFLOW | Bit describing the Overflow exception |
_EM_UNDERFLOW | Bit describing the Underflow exception |
_EM_INEXACT | Bit describing the Inexact Result exception |
_MCW_RC | Mask for the rounding mode field |
_RC_CHOP | Rounding mode value describing Round Toward Zero |
_RC_UP | Rounding mode value describing Round Up |
_RC_DOWN | Rounding mode value describing Round Down |
_RC_NEAR | Rounding 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, you would do:
_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);
The function _clearfp() clears all five
exception sticky flags, and returns their previous value. The macros
given in Table 4.8,
for example _EM_INVALID, _EM_ZERODIVIDE,
can be used to test bits of the returned result.
_clearfp() has the following prototype:
unsigned _clearfp(void);
The function _statusfp() returns the
current value of the exception sticky flags. You can use the macros
shown in Table 4.8 to
test bits of the returned result, for example, _EM_INVALID, _EM_ZERODIVIDE.
_statusfp has the following prototype:
unsigned _statusfp(void);