Oracle Solaris Studio 12.4 Man Pages

印刷ビューの終了

更新: January 2015
 
 

ieee_flags(3M)

名前

ieee_flags - 浮動小数点丸めモードと例外フラグにアクセスする

形式

cc [ flag ... ] file ...  -lsunmath -lm [ library ... ]
#include <sunmath.h>

int ieee_flags(const char *action, const char *mode,
     const char *in, char **out);

説明

この関数を使用すると、ANSI/IEEE 規格 754-1985 で規定されている浮動小数点丸めモードと例外フラグにアクセスできます。actionmodein 引数は、実行する演算を指定するための大文字と小文字が区別されない文字列へのポインタです。無効な引数文字列を指定したり、引数を無効な組み合わせで指定したりすると、未定義の結果が生じます。out 引数は、char * 型のオブジェクトへのポインタです。action が “get” の場合、*out は、要求された情報を提供する読み取り専用文字列へのポインタに設定されます。それ以外の action 値の場合、*out は変更されません。

action には、“get”、“set”、“clear”、“clearall” という 4 つの有効な値があります。action が “clearall” の場合、ieee_flags() はデフォルトの丸めモード (丸め方向は nearest、丸め精度は extended) を復元し、例外発生フラグをすべてクリアします。modein は無視されます。

action が “get”、“set”、または “clear” の場合、mode には次のいずれかを指定できます。

 
“direction”       ... current rounding direction mode
“precision”       ... current rounding precision mode
“exception”       ... accrued exception flag status

action が “clear” で、mode が “direction” の場合、ieee_flags() は丸め方向を nearest に設定します。action が “clear” で、mode が “precision” の場合、ieee_flags() は丸め精度を extended に設定します。どちらの場合も、in は無視されます。

action が “clear” で、mode が “exception” の場合、ieee_flags()in で指定された例外発生フラグをクリアします。in には、次のいずれかを指定できます。

 
“inexact”
“underflow”
“overflow”
“invalid”         ... invalid operation exception
“division”        ... division by zero exception
“all”             ... all five exceptions above
“common”          ... invalid, overflow, and division exceptions

action が “set” で、mode が “direction” の場合、ieee_flags() は丸め方向を in で指定されたモードに設定します。in には、次のいずれかを指定できます。

 
“nearest”         ... round toward nearest
“tozero”          ... round toward zero
“negative”        ... round toward negative infinity
“positive”        ... round toward positive infinity

action が “set” で、mode が “precision” の場合、ieee_flags() は丸め精度を in で指定されたモードに設定します。in には、次のいずれかを指定できます。

 
“extended”
“double”
“single”
 

action が “;set” で、mode が “exception” の場合、ieee_flags()in で指定された例外発生フラグを設定します。in には、上記のリストに示した例外文字列のいずれかを指定できます。

action が “get” で、mode が “direction” の場合、ieee_flags() は *out を現在の丸め方向に対応する丸め方向モードの文字列 (上記のリストを参照) に設定します。action が “get” で、mode が “precision” の場合、ieee_flags() は *out を現在の丸め精度に対応する丸め精度モードの文字列 (上記のリストを参照) に設定します。どちらの場合も、in は無視されます。

action が “get” で、mode が “exception” の場合、ieee_flags() は *out を次の文字列のいずれかに設定します。

 
(a) “not available” if accrued exception flags are not available,
(b) “” (the empty string) if there are no accrued exceptions,
(c) the accrued exception that has the highest priority according 
    to the list below

     (1) the exception named by in,
     (2) “invalid”,
     (3) “overflow”,
     (4) “division”,
     (5) “underflow”,
     (6) “inexact”.

戻り値

戻り値

action が “get” の場合、戻り値は <sys/ieeefp.h> に定義されているさまざまな enum 型の値を使用して、要求された情報をエンコードします。具体的には、mode が “direction” の場合、ieee_flags() は現在の丸め方向に対応する enum fp_direction_type 値を返します。mode が “precision” の場合、ieee_flags() は現在の丸め精度に対応する enum fp_precision_type 値を返します。mode が “exception” の場合、ieee_flags() はすべての例外発生フラグのビット単位の「論理和」を返します。各例外に対応するビット位置は、enum fp_exception_type で定義されています。その他の mode 値の場合、ieee_flags() は 0 を返します。

action が “set” の場合、ieee_flags() は、要求されたモードを設定できない場合 (ハードウェアでサポートされていない場合など) は 1 を返し、それ以外の場合は 0 を返します。

その他のすべての action 値の場合、ieee_flags() は 0 を返します。

 
#include <sunmath.h>

char *out;
int k;

/* report rounding precision */
(void) ieee_flags("get", "precision", "", &out);
printf("current rounding precision is %s\n", out);

/* set rounding direction to round toward zero */
k = ieee_flags("set", "direction", "tozero", &out);
if (k)
     printf("cannot set rounding direction\n");

/* clear all exception flags */
(void) ieee_flags("clear", "exception", "all", &out);

...
... (code that generates three exceptions: overflow, invalid, inexact)
...

/* restore default rounding direction */
(void) ieee_flags("clear", "direction", "", &out);

/* get accrued exceptions */
k = ieee_flags("get", "exception", "overflow", &out);

この時点で、out は文字列 “overflow” (SPARC では、k = 25 = 0x19) を指しています。

属性

次の属性については、attributes(5) を参照してください。

属性タイプ
属性値
インタフェースの安定性
確実
MT レベル
MT-安全

関連項目

feclearexcept(3M)、fegetenv(3M), fegetexceptflag(3M)、fegetprec(3M)、fegetround(3M)、feholdexcept(3M)、feraiseexcept(3M)、fetestexcept(3M)、feupdateenv(3M)、fex_merge_flags(3M)、fex_set_handling(3M)、ieee_handler(3M)、attributes(5)

SPARC には、丸め精度モードがありません。mode が “precision” の場合、ieee_flags() はアクションを実行せずに、0 を返します。

x86 では、丸め精度モードによって、基本的な x87 浮動小数点算術命令のみが影響を受けます。SSE 命令は影響を受けません。