_clear87_clearfp

获取并清除浮点状态字。

语法

unsigned int _clear87( void );
unsigned int _clearfp( void );

返回值

返回值中的位表示调用 _clear87_clearfp 之前的浮点状态。 有关由 _clear87 返回的位的完整定义,请参阅 Float.h。 许多数学库函数修改了 8087/80287 状态字,结果不可预知。 在浮点状态字的已知状态之间执行的浮点运算越少,_clear87_status87 的返回值就会越可靠。

备注

_clear87 函数将清除浮点状态字中的异常标记,将繁忙位设置为 0,并返回状态字。 浮点状态字是 8087/80287 状态字和通过 8087/80287 异常处理程序检测到的其他条件(如浮点堆栈上溢和下溢)组合而成。

_clearfp_clear87 例程的一个与平台无关的、可移植的版本。 它与 Intel (x86) 平台上的 _clear87 相同,并且也受 x64 和 ARM 平台的支持。 若要确保你的浮点代码可移植到 x64 和 ARM,请使用 _clearfp。 如果你只面向 x86 平台,可以使用 _clear87_clearfp

当使用 /clr(公共语言运行时编译)进行编译时,这些函数将被弃用,因为公共语言运行时仅支持默认的浮点精度。

要求

例程 必需的标头
_clear87 <float.h>
_clearfp <float.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// crt_clear87.c
// compile with: /Od

// 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>

int 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() );
}
Status: 0000 - clear
Status: 0003 - inexact, underflow
Status: 80000 - denormal

另请参阅

数学和浮点支持
_control87_controlfp__control87_2
_status87_statusfp_statusfp2