Share via


_status87, _statusfp, _statusfp2

取得浮點狀態字組。

語法

unsigned int _status87( void );
unsigned int _statusfp( void );
void _statusfp2(unsigned int *px86, unsigned int *pSSE2)

參數

px86
這個位址會填入 x87 浮點單位的狀態字組。

pSSE2
這個位址會填入 SSE2 浮點單位的狀態字組。

傳回值

針對 _status87_statusfp,所傳回值中的位元表示浮點狀態。 如需 _statusfp 所傳回位元的定義,請參閱 FLOAT.H 包含檔案。 許多數學程式庫函式都會修改浮點狀態字組,伴隨著無法預期的結果。 最佳化可以重新排列、合併和消除 _status87_statusfp 和相關函式呼叫的浮點運算。 使用 /Od (Disable (Debug)) 編譯器選項或 fenv_access pragma 指示詞來防止重新排序浮點運算的優化。 如果在浮點狀態字組之已知狀態之間執行較少浮點運算,則來自 _clearfp_statusfp 的傳回值以及 _statusfp2 的傳回參數更加可靠。

備註

_statusfp 函式會取得浮點狀態字組。 狀態字組是浮點處理器狀態與浮點例外狀況處理常式所偵測到之其他條件的組合,例如浮點堆疊溢位和反向溢位。 傳回狀態字組的內容之前,會檢查取消遮罩的例外狀況。 換句話說,呼叫端會收到擱置例外狀況的通知。 在 x86 平台上,_statusfp 會傳回 x87 與 SSE2 浮點狀態的組合。 在 x64 平臺上,傳回的狀態是以 SSE 的 MXCSR 狀態為基礎。 在 ARM64 平臺上, _statusfp 從 FPSCR 暫存器傳回狀態。

_statusfp_status87 之與平台無關的可攜式版本。 這與 Intel (x86) 平臺上相同 _status87 ,而且 x64 和 ARM64 平臺也支援。 若要確保您的浮點程式碼可移植到所有結構,請使用 _statusfp。 如果您只以 x86 平臺為目標,則可以使用 _status87_statusfp

建議針對同時具有 x87 和 SSE2 浮點處理器的晶片 (例如 Pentium IV) 使用 _statusfp2。 對於 _statusfp2,針對 x87 或 SSE2 浮點處理器使用浮點狀態字組來填入位址。 對於支援 x87 和 SSE2 浮點處理器的晶片,如果 _statusfp_controlfp 或 已使用 , EM_AMBIGUOUS 且動作模棱兩可,因為它可以參考 x87 或 SSE2 浮點狀態字組,則會設定為 1。 只有 x86 平台才支援 _statusfp2 函式。

這些函式不適用於 /clr (Common Language Runtime Compilation), 因為 Common Language Runtime (CLR) 僅支援預設浮點精確度。

需求

常式 必要的標頭
_status87, _statusfp, _statusfp2 <float.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_statusfp.c
// Build by using: cl /W4 /Ox /nologo crt_statusfp.c
// This program creates various floating-point errors and
// then uses _statusfp to display messages that indicate these problems.

#include <stdio.h>
#include <float.h>
#pragma fenv_access(on)

double test( void )
{
   double a = 1e-40;
   float b;
   double c;

   printf("Status = 0x%.8x - clear\n", _statusfp());

   // Assignment into b is inexact & underflows:
   b = (float)(a + 1e-40);
   printf("Status = 0x%.8x - inexact, underflow\n", _statusfp());

   // c is denormal:
   c = b / 2.0;
   printf("Status = 0x%.8x - inexact, underflow, denormal\n",
            _statusfp());

   // Clear floating point status:
   _clearfp();
   return c;
}

int main(void)
{
   return (int)test();
}
Status = 0x00000000 - clear
Status = 0x00000003 - inexact, underflow
Status = 0x00080003 - inexact, underflow, denormal

另請參閱

數學和浮點支援
_clear87, _clearfp
_control87, _controlfp, __control87_2