Name
_control87 - Gets and sets floating-point control word.
Syntax
#include <float.h>
unsigned int _control87(new, mask)
unsigned int new;
unsigned int mask;
Description
The _control87 function gets and sets the floating-point
control word. The floating-point control word allows the
program to change the precision, rounding, and infinity
modes in the floating-point math package. Floating-point
exceptions can also be masked or unmasked using the
_control87 function.
If the value for mask is equal to 0, then _control87 gets
the floating-point control word. If mask is nonzero, then a
new value for the control word is set in the following
manner: for any bit that is on (equal to 1) in mask, the
corresponding bit in new is used to update the control word.
To put it another way,
fpcntrl = ((fpcntrl & ~mask) | (new & mask))
where fpcntrl is the floating-point control word.
Return Value
The bits in the value returned indicate the floating-point
control state. See the float.h include file for a complete
definition of the bits returned by _control87.
See Also
_clear87(DOS), _status87(DOS)
Example
#include <stdio.h> #include <float.h>
double a = .1;
main( )
{
/* get control word: */
printf("control = %.4x\n", _control87(0,0));
printf("a*a = .01 = %.15e\n",a*a);
/* set precision to 24 bits: */
_control87(PC_24,MCW_PC);
printf("a*a = .01 (rounded to 24 bits) =
%.15e\n",a*a);
/* restore to initial default: */
_control87(CW_DEFAULT,0xFFFF);
printf("a*a = .01 = %.15e\n",a*a);
}
This program uses _control87 to output the control word, set
the precision to 24 bits, and reset the status to the
default.
(printed 6/18/89)