Format
#include <float.h> /* also in <builtin.h> */ unsigned int _clear87(void);
Language Level: Extension
_clear87 gets the floating-point status word and
then clears it. The floating-point status word is a combination
of the numeric coprocessor status word and other conditions that
the numeric exception handler detects, such as floating-point
stack overflow and underflow.
_clear87 affects only the current thread. It does not affect any other threads that may be processing.
Return Value
The bits in the value returned reflect
the floating-point status before the call to _clear87 was made.
Example
This example takes a number close to 0 as
a double and assigns it to a float. The result is a loss of
significance, y becomes a denormal number, and the underflow bit
of the floating-point status word is set. _clear87 gets the
current floating-point status word and then clears it, and printf
prints it as immediate data. The result shows the change in the
floating-point word because of the loss of significance.
The program then assigns the denormal y to another variable, causing the denormal bit to be set in the floating-point status word. Again, _clear87 gets the current status word and clears it, and printf prints it to the screen.
#include <stdio.h> #include <float.h>
double a = 1e-40; double b; float y;
int main(void)
{
unsigned int statword;
unsigned int old_cw;
/* change control word to mask all exceptions */
_control87(0x037f, 0xffff);
/* Assignment of the double to the float y is inexact; */ /* the underflow bit is set. */
y = a;
statword = _clear87();
printf("floating-point status = 0x%.4x after underflow\n", statword);
statword = _status87();
printf("cleared floating-point status word = 0x%.4x\n", statword);
/* reset floating point status word */
_fpreset();
/* change control word to mask all exception */
_control87(0x037f, 0xffff);
/* Reassigning the denormal y to the double b */ /* causes the denormal bit to be set. */
b = y;
statword = _clear87();
printf("floating-point status = 0x%.4x for denormal\n", statword);
/* reset floating point status word */
_fpreset(); return 0;
/*************************************************************************
The output should be:
floating-point status = 0x0030 after underflow
cleared floating-point status word = 0x0000
floating-point status = 0x0002 for denormal
*************************************************************************/
}
![]()
_control87 -- Set
Floating-Point Control Word
_status87 -- Get
Floating-Point Status Word
_fpreset --
Reset Floating-Point Unit
<float.h>