Format
#include <float.h> /* also in <builtin.h> */ unsigned int _control87(unsigned int new, unsigned int mask);
Language Level: Extension
_control87 gets the current floating-point control word and then
sets it. The floating-point control word specifies the precision,
rounding, and infinity modes of the floating-point chip.
You can mask or unmask current floating-point exceptions using _control87. If the value for the mask is equal to 0, _control87 gets the floating-point control word. If the mask is nonzero, _control87 sets a new value for the control word in the manner described below, and returns the previous value of the control word. For any bit in the mask equal to 1, the corresponding bit in new updates the control word. This is equivalent to the expression:
fpcntrl = ((fpcntrl & ~ mask) | (new & mask))
where fpcntrl is the floating-point control word.
_control87 is used for the current thread only. It does not affect any other threads that may be processing.
Warning: If you change the content of the floating-point control word:
Return Value
The bits in the returned value reflect the
floating-point control word before the call.
Example
This example prints the initial control word in
hexadecimal, and then illustrates different representations of
0.1, depending on the precision.
#include <stdio.h> #include <float.h>
double a = .13;
int main(void)
{
printf("control = 0x%.4x\n", _control87(CW_DEFAULT, 0));/* Get control word*/
printf("a*a = .0169 = %.15e\n", a *a);
_control87(PC_24, MCW_PC); /* Set precision to 24 bits */
printf("a*a = .0169 (rounded to 24 bits) = %.15e\n", a *a);
_control87(CW_DEFAULT, 0xffff); /* Restore to initial default */
printf("a*a = .0169 = %.15e\n", a *a);
return 0;
/****************************************************************************
The output should be similar to:
control = 0x0362
a*a = .0169 = 1.690000000000000e-02
a*a = .0169 (rounded to 24 bits) = 1.690000057220459e-02
a*a = .0169 = 1.690000000000000e-02
****************************************************************************/
}
![]()
_clear87 -- Clear Floating-Point
Status Word
_status87 -- Get Floating-Point
Status Word
_fpreset -- Reset
Floating-Point Unit
signal -- Handle Interrupt
Signals
<float.h>
Exception Handling for
Floating-Point Exceptions