Share via


_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 編譯時 會取代這些函式,因為 Common Language Runtime 只支援預設浮點精確度。

需求

常式 必要的標頭
_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