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

互換性の詳細については、「 Compatibility」を参照してください。

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