「C言語/標準ライブラリ/fenv.h」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
→‎関数: F.8.6など加筆
タグ: 2017年版ソースエディター
54 行
</syntaxhighlight>
 
=== 浮動小数点例外<!--7.6.2 Floating-point exceptions--> ===
=== feclearexcept関数 ===
以下の関数は、浮動小数点のステータス・フラグへのアクセスを提供します 219) これらの関数のint入力引数は、浮動小数点例外のサブセットを表しており、ゼロ、または1つ以上の浮動小数点例外マクロのビットごとのORを指定できます(例:FE_OVERFLOW | FE_INEXACTなど)。それ以外の引数値の場合、これらの関数の動作は不定です。
 
==== feclearexcept関数 ====
ISO/IEC 9899:2017 § 7.6.2.1 ''The feclearexcept function''<ref name="jtc1-sc22-wg14-n2596-7.6.2.1">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
67 ⟶ 70行目:
</syntaxhighlight>
; 機能
: feclearexcept関数は、引数exceptsで指定されたサポート対象の浮動小数点例外をクリアしようとします。
<!--
2 The feclearexcept function attempts to clear the supported floating-point exceptions represented by its argument.
-->
; 返却値
: feclearexcept関数は、引数exceptsが0の場合、または指定されたすべての例外が正常にクリアされた場合には0を返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The feclearexcept function returns zero if the excepts argument is zero or if all the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.
-->
 
==== fegetexceptflag関数 ====
ISO/IEC 9899:2017 § 7.6.2.2 ''The fegetexceptflag function''<ref name="jtc1-sc22-wg14-n2596-7.6.2.2">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
85 ⟶ 90行目:
; 形式 : <syntaxhighlight lang=C>
#include <fenv.h>
int fegetexceptflag(fexcept_t *flagp, int excepts);
</syntaxhighlight>
 
<!--
#pragma STDC FENV_ACCESS ON pragma, and assuming the default state is “off”, just one evaluation of x + 1 would suffice.
set or clear. An implementation may endow floating-point status flags with more information — for example, the address of
the code which first raised the floating-point exception; the functions fegetexceptflag and fesetexceptflag deal with
the full content of flags.
-->
; 機能
: fegetexceptflag関数は、引数exceptsで示される浮動小数点のステータスフラグの状態を、実装で定義された表現で、引数flagpで指されるオブジェクトに格納しようとする。
<!--
2 The fegetexceptflag function attempts to store an implementation-defined representation of the states of the floating-point status flags indicated by the argument excepts in the object pointed to by the argument flagp.
-->
; 返却値
: fegetexceptflag関数は、表現の保存に成功した場合は0を返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The fegetexceptflag function returns zero if the representation was successfully stored. Otherwise,it returns a nonzero value.
-->
 
==== feraiseexcept関数 ====
ISO/IEC 9899:2017 § 7.6.2.3 ''The feraiseexcept function''<ref name="jtc1-sc22-wg14-n2596-7.6.2.3">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
115 ⟶ 117行目:
</syntaxhighlight>
; 機能
: feraiseexcept関数は、引数exceptsで表されるサポートされた浮動小数点例外を発生させようとします<ref>この効果は、算術演算によって発生する浮動小数点例外と同様のものを意図しています。そのため、有効な トラップが取られます。[[#§F.8.6|F.8.6]] の仕様も同じ精神に基づいています。</ref>。これらの浮動小数点例外を発生させる順序は、[[#§F.8.6|F.8.6]] ''Changing the environment'' に記載されている場合を除き、特定されていません。feraiseexcept 関数が "overflow" または "underflow" 浮動小数点例外を発生させるときに "inexact" 浮動小数点例外を追加で発生させるかどうかは、実装で定義されます。
<!--
2 The feraiseexcept function attempts to raise the supported floating-point exceptions represented by its argument.220) The order in which these floating-point exceptions are raised is unspecified,except as stated in F.8.6. Whether the feraiseexcept function additionally raises the “inexact”floating-point exception whenever it raises the “overflow” or “underflow” floating-point exception is implementation-defined.
by its argument.220) The order in which these floating-point exceptions are raised is unspecified,except as stated in F.8.6. Whether the feraiseexcept function additionally raises the “inexact”
floating-point exception whenever it raises the “overflow” or “underflow” floating-point exception
is implementation-defined.
-->
; 返却値
: feraiseexcept関数は、excepts引数が0の場合、または指定されたすべての例外が正常に発生した場合には0を返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The feraiseexcept function returns zero if the excepts argument is zero or if all the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.
exceptions were successfully raised. Otherwise, it returns a nonzero value.
-->
 
==== fesetexceptflag関数 ====
ISO/IEC 9899:2017 § 7.6.2.4 ''The fesetexceptflag function''<ref name="jtc1-sc22-wg14-n2596-7.6.2.4">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
140 行
</syntaxhighlight>
; 機能
: fesetexceptflag関数は、引数exceptsが示す浮動小数点ステータス・フラグを、flagpが指すオブジェクトに格納されている状態に設定しようとします。flagpの値は、第2引数が少なくともexceptsで示される浮動小数点例外を表すfegetexceptflagの以前の呼び出しによって設定されていなければなりません。この関数は、浮動小数点の例外を発生させず、フラグの状態を設定するだけです。
<!--
2 The fesetexceptflag function attempts to set the floating-point status flags indicated by the argument excepts to the states stored in the object pointed to by flagp. The value of *flagp shall have been set by a previous call to fegetexceptflag whose second argument represented at least those floating-point exceptions represented by the argument excepts. This function does not raise floating-point exceptions, but only sets the state of the flags.
argument excepts to the states stored in the object pointed to by flagp. The value of *flagp shall
have been set by a previous call to fegetexceptflag whose second argument represented at least
those floating-point exceptions represented by the argument excepts. This function does not raise
floating-point exceptions, but only sets the state of the flags.
-->
; 返却値
fesetexceptflag関数は、引数exceptsがゼロの場合、または指定されたすべてのフラグが適切な状態に正常に設定された場合にはゼロを返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The fesetexceptflag function returns zero if the excepts argument is zero or if all the specified flags were successfully set to the appropriate state. Otherwise, it returns a nonzero value.
flags were successfully set to the appropriate state. Otherwise, it returns a nonzero value.
-->
 
==== fetestexcept関数 ====
ISO/IEC 9899:2017 § 7.6.2.5 ''The fetestexcept function''<ref name="jtc1-sc22-wg14-n2596-7.6.2.5">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
166 ⟶ 163行目:
</syntaxhighlight>
; 機能
fetestexcept関数は、浮動小数点例外フラグの指定されたサブセットのうち、どれが現在設定されているかを判定します。引数exceptsは、問い合わせを行う浮動小数点ステータス・フラグを指定します。 この関数によって発生した浮動小数点例外のトラップが取られます。[[#§F.8.6|F.8.6]]の仕様も同じ精神に基づいています。
<!--
2 The fetestexcept function determines which of a specified subset of the floating-point exception flags are currently set. The excepts argument specifies the floating-point status flags to be queried. traps for floating-point exceptions raised by this function are taken. The specification in F.8.6 is in the same spirit.
queried.
traps for floating-point exceptions raised by this function are taken. The specification in F.8.6 is in the same spirit.
-->
; 返却値
: fetestexcept関数は、引数exceptsに含まれる現在設定されている浮動小数点例外に対応する浮動小数点例外マクロのビットごとのORの値を返します。
<!--
3 The fetestexcept function returns the value of the bitwise OR of the floating-point exception macros corresponding to the currently set floating-point exceptions included in excepts.
macros corresponding to the currently set floating-point exceptions included in excepts.
-->
 
=== 丸め<!--7.6.3 Rounding--> ===
fegetround および fesetround 関数は、丸め方向モードの制御を行います。
<!--
1 The fegetround and fesetround functions provide control of rounding direction modes.
-->
==== fegetround関数 ====
ISO/IEC 9899:2017 § 7.6.3.1 ''The fegetround function''<ref name="jtc1-sc22-wg14-n2596-7.6.3.1">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
194 ⟶ 191行目:
</syntaxhighlight>
; 機能
: fegetround関数は、現在の丸め方向を取得します。
<!--
2 The fegetround function gets the current rounding direction.
-->
; 返却値
: fegetround関数は、現在の丸め込み方向を表す丸め込み方向マクロの値を返し、そのような丸め込み方向マクロがない場合や現在の丸め込み方向が決定できない場合は負の値を返します。
<!--
3 The fegetround function returns the value of the rounding direction macro representing the current rounding direction or a negative value if there is no such rounding direction macro or the current rounding direction is not determinable.
rounding direction or a negative value if there is no such rounding direction macro or the current
rounding direction is not determinable.
-->
 
217 ⟶ 214行目:
</syntaxhighlight>
; 機能
: fesetround 関数は、引数 round で表される丸め方向を確立する。引数 round が丸め方向マクロの値と一致しない場合、丸め方向は変更されない。
<!--
2 The fesetround function establishes the rounding direction represented by its argument round. If the argument is not equal to the value of a rounding direction macro, the rounding direction is not changed.
the argument is not equal to the value of a rounding direction macro, the rounding direction is not
changed.
-->
; 返却値
: fesetround関数は、要求された丸め方向が確立されている場合に限り、ゼロを返します。
<!--
3 The fesetround function returns zero if and only if the requested rounding direction was established.
-->
 
=== 環境<!--7.6.4 Environment--> ===
このセクションの関数は、ステータス・フラグやコントロール・モードといった浮動小数点環境を一つの実体として管理します。
<!--
1 The functions in this section manage the floating-point environment — status flags and control modes — as one entity.
modes — as one entity.
-->
==== fegetenv関数 ====
ISO/IEC 9899:2017 § 7.6.4.1 ''The fegetenv function''<ref name="jtc1-sc22-wg14-n2596-7.6.4.1">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
245 ⟶ 242行目:
</syntaxhighlight>
; 機能
: fegetenv関数は、現在の浮動小数点環境をenvpが指すオブジェクトに格納しようとします。
<!--
2 The fegetenv function attempts to store the current floating-point environment in the object pointed to by envp.
to by envp.
-->
; 返却値
: fegetenv関数は、環境の保存に成功した場合はゼロを返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The fegetenv function returns zero if the environment was successfully stored. Otherwise, it returns a nonzero value.
a nonzero value.
-->
 
==== feholdexcept関数 ====
ISO/IEC 9899:2017 § 7.6.4.2 ''The feholdexcept function''<ref name="jtc1-sc22-wg14-n2596-7.6.4.2">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
268 ⟶ 265行目:
</syntaxhighlight>
; 機能
: feholdexcept関数は、引数envpが指すオブジェクトに現在の浮動小数点環境を保存し、浮動小数点のステータス・フラグをクリアした後、利用可能であれば、すべての浮動小数点例外に対してノンストップ(浮動小数点例外時に続行)モードをインストールします。
<!--
2 The feholdexcept function saves the current floating-point environment in the object pointed to by envp, clears the floating-point status flags, and then installs a non-stop (continue on floating-point exceptions) mode, if available, for all floating-point exceptions.
envp, clears the floating-point status flags, and then installs a non-stop (continue on floating-point
exceptions) mode, if available, for all floating-point exceptions.
-->
; 返却値
: feholdexcept関数は、ノンストップ浮動小数点例外処理のインストールに成功した場合にのみ、ゼロを返します。
<!--
3 The feholdexcept function returns zero if and only if non-stop floating-point exception handling was successfully installed.
was successfully installed.
-->
 
==== fesetenv関数 ====
ISO/IEC 9899:2017 § 7.6.4.3 ''The fesetenv function''<ref name="jtc1-sc22-wg14-n2596-7.6.4.3">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
292 ⟶ 288行目:
</syntaxhighlight>
; 機能
: fesetenv関数は、envpが指すオブジェクトで表される浮動小数点環境を確立しようとするものです。引数envpは、fegetenvまたはfeholdexceptの呼び出しによって設定されたオブジェクトを指すか、または浮動小数点環境マクロに等しくなければならない。
feholdexceptの呼び出しによって設定されたオブジェクトを指すか、または浮動小数点環境マクロに等しい。fesetenvは単にシステムをインストールするだけで、ノンストップモードのみを提供し、その後のインストールは些細なことであることに注意してください。このようなシステムでは、feholdexcept関数をfeupdateenv関数と組み合わせて使用し、呼び出し元から偽の浮動小数点例外を隠すルーチンを書くことができます。
feholdexcept関数は、その引数で表される浮動小数点ステータス・フラグの状態を監視し、これらの浮動小数点例外を発生させません。
<!--
2 The fesetenv function attempts to establish the floating-point environment represented by the object pointed to by envp. The argument envp shall point to an object set by a call to fegetenv or
feholdexcept, or equal a floating-point environment macro. Note that fesetenv merely installs the system provides only the non-stop mode then installing it is trivial. For such systems, the feholdexcept function can be used in conjunction with the feupdateenv function to write routines that hide spurious floating-point exceptions from their callers.
object pointed to by envp. The argument envp shall point to an object set by a call to fegetenv or
feholdexcept, or equal a floating-point environment macro. Note that fesetenv merely installs
the system provides only the non-stop mode then installing it is trivial. For such systems, the feholdexcept function can be
used in conjunction with the feupdateenv function to write routines that hide spurious floating-point exceptions from their
callers.
 
the state of the floating-point status flags represented through its argument, and does not raise these floating-point exceptions.
floating-point exceptions.
-->
; 返却値
: fesetenv関数は、環境の構築に成功した場合は0を返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The fesetenv function returns zero if the environment was successfully established. Otherwise, it returns a nonzero value.
returns a nonzero value.
-->
 
==== feupdateenv関数 ====
ISO/IEC 9899:2017 § 7.6.4.4 ''The feupdateenv function''<ref name="jtc1-sc22-wg14-n2596-7.6.4.4">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
322 ⟶ 316行目:
</syntaxhighlight>
; 機能
: feupdateenv関数は、現在発生している浮動小数点例外を自動変数に保存し、envpが指すオブジェクトが表す浮動小数点環境をインストールしてから、保存した浮動小数点例外を発生させようとします。引数envpは、feholdexceptまたはfegetenvの呼び出しによって設定されたオブジェクトを指すか、または浮動小数点環境マクロに等しくなければなりません。
<!--
2 The feupdateenv function attempts to save the currently raised floating-point exceptions in its automatic storage, install the floating-point environment represented by the object pointed to by envp, and then raise the saved floating-point exceptions. The argument envp shall point to an object set by a call to feholdexcept or fegetenv, or equal a floating-point environment macro.
automatic storage, install the floating-point environment represented by the object pointed to by
envp, and then raise the saved floating-point exceptions. The argument envp shall point to an object
set by a call to feholdexcept or fegetenv, or equal a floating-point environment macro.
-->
; 返却値
: feupdateenv関数は、すべてのアクションが正常に実行された場合はゼロを返します。それ以外の場合は、ゼロ以外の値を返します。
<!--
3 The feupdateenv function returns zero if all the actions were successfully carried out. Otherwise, it returns a nonzero value.
returns a nonzero value.
-->
 
* N2176 C17 ballot ISO/IEC 9899:2017 {{Anchors|§F.8.6}} ''Changing the environment''<ref name="jtc1-sc22-wg14-n2596-F.8.6">{{cite book
| url = http://www.open-std.org/jtc1/sc22/wg14/www/docs/c17_updated_proposed_fdis.pdf
| archiveurl = https://web.archive.org/web/20181230041359/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
| archivedate = 2018-12-30
| title = N2176 C17 ballot ISO/IEC 9899:2017
| page = 374, §F.8.6 ''Changing the environment''
| publisher = ISO/IEC JTC1/SC22/WG14}}</ref>.
§6.5 ''Expressions'' で定義された操作や、標準ライブラリで定義された関数やマクロは、以下のように変更されます。標準ライブラリで定義されている関数やマクロは、それぞれの仕様(IEC 60559への準拠を含む)に従って、浮動小数点のステータスフラグや制御モードを変更する。それ以外の場合は、フラグや制御モードを(ユーザが検知できるように)変更しない。それ以外の場合は、フラグやモードを変更しません。
 
<fenv.h>のferraiseexcept関数の引数が、IEC 60559で有効なアトミック操作のための一致した浮動小数点例外(すなわち、"overflow "と "inexact"、または "underflow "と "inexact")を表している場合、"overflow "または "underflow "が "inexact "の前に発生します。
 
double_t x = 1.1e75;
 
は、表現の評価方法に関わらず、翻訳時に行うことができます。
 
==脚註==