_clear87, _clearfp

Get and clear the floating-point status word.

unsignedint_clear87(void);

unsignedint_clearfp(void);

Routine Required Header Compatibility
_clear87 <float.h> Win 95, Win NT
_clearfp <float.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

The bits in the value returned indicate the floating-point status before the call to _clear87 or _clearfp. See FLOAT.H for a complete definition of the bits returned by _clear87. Many of the math library functions modify the 8087/80287 status word, with unpredictable results. Return values from _clear87 and _status87 become more reliable as fewer floating-point operations are performed between known states of the floating-point status word.

Remarks

The _clear87 function clears the exception flags in the floating-point status word, sets the busy bit to 0, and returns the status word. The floating-point status word is a combination of the 8087/80287 status word and other conditions detected by the 8087/80287 exception handler, such as floating-point stack overflow and underflow.

_clearfp is a platform-independent, portable version of the _clear87 routine. It is identical to _clear87 on IntelĀ® (x86) platforms and is also supported by the MIPSĀ® and ALPHA platforms. To ensure that your floating-point code is portable to MIPS or ALPHA, use _clearfp. If you are only targeting x86 platforms, you can use either _clear87 or _clearfp.

Example

/* CLEAR87.C: This program creates various floating-point
 * problems, then uses _clear87 to report on these problems.
 * Compile this program with Optimizations disabled (/Od).
 * Otherwise the optimizer will remove the code associated with
 * the unused floating-point values.
 */

#include <stdio.h>
#include <float.h>

void main( void )
{
   double a = 1e-40, b;
   float x, y;

   printf( "Status: %.4x - clear\n", _clear87()  );

   /* Store into y is inexact and underflows: */
   y = a;
   printf( "Status: %.4x - inexact, underflow\n", _clear87() );

   /* y is denormal: */
   b = y;
   printf( "Status: %.4x - denormal\n", _clear87() );
}

Output

Status: 0000 - clear
Status: 0003 - inexact, underflow
Status: 80000 - denormal

Floating-Point Support Routines

See Also   _control87, _status87