.\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl) .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" .\" 2000-08-14 added GNU additions from Andreas Jaeger .\" 2000-12-05 some changes inspired by acahalan's remarks .\" .\" Japanese Version Copyright (c) 2000-2001 NAKANO Takeo .\" and Copyright (c) 2008 Akihiro MOTOKI. .\" Translated 2001-02-08, NAKANO Takeo .\" Updated 2003-10-15, Kentaro Shirakata .\" Updated 2005-02-26, Akihiro MOTOKI .\" Updated 2008-09-16, Akihiro MOTOKI .\" .\"WORD: (floating-point) exception (浮動小数点) 例外 .\"WORD: rounding 丸め .\"WORD: opaque 内部の .\" .TH FENV 3 2008-08-11 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, .\"O fetestexcept, fegetenv, fegetround, feholdexcept, fesetround, .\"O fesetenv, feupdateenv, feenableexcept, fedisableexcept, .\"O fegetexcept \- floating-point rounding and exception handling feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, fetestexcept, fegetenv, fegetround, feholdexcept, fesetround, fesetenv, feupdateenv, feenableexcept, fedisableexcept, fegetexcept \- 浮動小数点の丸めと例外の取り扱い .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int feclearexcept(int " excepts ); .br .BI "int fegetexceptflag(fexcept_t *" flagp ", int " excepts ); .br .BI "int feraiseexcept(int " excepts ); .br .BI "int fesetexceptflag(const fexcept_t *" flagp ", int " excepts ); .br .BI "int fetestexcept(int " excepts ); .sp .B "int fegetround(void);" .br .BI "int fesetround(int " rounding_mode ); .sp .BI "int fegetenv(fenv_t *" envp ); .br .BI "int feholdexcept(fenv_t *" envp ); .br .BI "int fesetenv(const fenv_t *" envp ); .br .BI "int feupdateenv(const fenv_t *" envp ); .fi .sp .\"O Link with \fI\-lm\fP. \fI\-lm\fP でリンクする。 .\"O .SH DESCRIPTION .SH 説明 .\"O These eleven functions were defined in C99, and describe the handling .\"O of floating-point rounding and exceptions (overflow, zero-divide etc.). これらの 11 個の関数は C99 で定義されており、 浮動小数点の丸めと例外 (オーバーフロー、ゼロによる除算など) の取り扱いを規定する。 .\"O .SS Exceptions .SS 例外 .\"O The .\"O .I divide-by-zero .\"O exception occurs when an operation on finite numbers .\"O produces infinity as exact answer. .I divide-by-zero 例外は、有限の数値に対する演算が、 無限大の答えを生成するような場合に起こる。 .LP .\"O The .\"O .I overflow .\"O exception occurs when a result has to be represented as a .\"O floating-point number, but has (much) larger absolute value than the .\"O largest (finite) floating-point number that is representable. .I overflow 例外は、結果が浮動小数点数値で表記されなければならないのに、 その絶対値が表現可能な浮動小数点数の (有限の) 最大値よりも (ずっと) 大きくなってしまうような場合に起こる。 .LP .\"O The .\"O .I underflow .\"O exception occurs when a result has to be represented as a .\"O floating-point number, but has smaller absolute value than the smallest .\"O positive normalized floating-point number (and would lose much accuracy .\"O when represented as a denormalized number). .I underflow 例外は、結果が浮動小数点数値で表記されなければならないのに、 その絶対値が正の正規化浮動小数点数の最小値よりも 小さくなってしまう (そして 非正規化数で表現した場合に非常に精度を失ってしまう) ような場合に起こる。 .LP .\"O The .\"O .I inexact .\"O exception occurs when the rounded result of an operation .\"O is not equal to the infinite precision result. .\"O It may occur whenever .\"O .I overflow .\"O or .\"O .I underflow .\"O occurs. .I inexact 例外は、丸め後の演算結果が、 無限精度の結果と異なるような場合に起こる。 .I overflow 例外か .I underflow 例外が起きたときには、常にこの例外も起こる。 .LP .\"O The .\"O .I invalid .\"O exception occurs when there is no well-defined result .\"O for an operation, as for 0/0 or infinity \- infinity or sqrt(\-1). .I invalid 例外は、演算結果がうまく定義できない結果を生じるような場合に起こる。 例えば 0/0、無限大 \- 無限大、sqrt(\-1) など。 .\"O .SS "Exception handling" .SS 例外処理 .\"O Exceptions are represented in two ways: as a single bit .\"O (exception present/absent), and these bits correspond in some .\"O implementation-defined way with bit positions in an integer, .\"O and also as an opaque structure that may contain more information .\"O about the exception (perhaps the code address where it occurred). 例外の表し方には 2 つの方法がある。 ひとつは、単一のビットで (例外があったかなかったかを) 表す方法で、 これらのビットは整数のあるビット位置に対応し、ビットの対応付けは 実装依存である。もう一つは、内部構造体を使って表す方法で、 この方法の方が例外に関するより多くの情報 (例えば例外が起こったコードのアドレスなど) が含まれる。 .LP .\"O Each of the macros .\"O .BR FE_DIVBYZERO , .\"O .BR FE_INEXACT , .\"O .BR FE_INVALID , .\"O .BR FE_OVERFLOW , .\"O .B FE_UNDERFLOW .\"O is defined when the implementation supports handling .\"O of the corresponding exception, and if so then .\"O defines the corresponding bit(s), so that one can call .\"O exception handling functions, for example, using the integer argument .\"O .BR FE_OVERFLOW | FE_UNDERFLOW . .\"O Other exceptions may be supported. .\"O The macro .\"O .B FE_ALL_EXCEPT .\"O is the bitwise OR of all bits corresponding to supported exceptions. .BR FE_DIVBYZERO , .BR FE_INEXACT , .BR FE_INVALID , .BR FE_OVERFLOW , .B FE_UNDERFLOW の各マクロは、それぞれ対応する例外の処理を 実装がサポートしている場合に定義される。 このとき対応するビットをそれぞれ定義することになるので、 例外処理関数の呼び出しを、例えば .BR FE_OVERFLOW | FE_UNDERFLOW という整数の引き数を用いて行うことができる。 他の例外もサポートされているかもしれない。 .B FE_ALL_EXCEPT マクロは、サポートされている例外に対応するビットが全てセットされている (サポートされている例外全ての論理和である)。 .PP .\"O The .\"O .BR feclearexcept () .\"O function clears the supported exceptions represented by the bits .\"O in its argument. .BR feclearexcept () 関数は、引き数 .I excepts のビット列で指定された例外をクリアする (処理は実装でサポートされている例外についてのみ行われる)。 .LP .\"O The .\"O .BR fegetexceptflag () .\"O function stores a representation of the state of the exception flags .\"O represented by the argument .\"O .I excepts .\"O in the opaque object .\"O .IR *flagp . .BR fegetexceptflag () 関数は、引き数 .I excepts で指定された例外フラグの状態を .I *flagp が指す内部オブジェクトに保存する。 .LP .\"O The .\"O .BR feraiseexcept () .\"O function raises the supported exceptions represented by the bits in .\"O .IR excepts . .BR feraiseexcept () 関数は、 .I excepts のビット列で指定された例外のうち、 実装がサポートしているものを発生させる。 .LP .\"O The .\"O .BR fesetexceptflag () .\"O function sets the complete status for the exceptions represented by .\"O .I excepts .\"O to the value .\"O .IR *flagp . .\"O This value must have been obtained by an earlier call of .\"O .BR fegetexceptflag () .\"O with a last argument that contained all bits in .\"O .IR excepts . .BR fesetexceptflag () 関数は、 .I excepts で指定された例外に対応するフラグの状態を .I *flagp の値に設定する。 .I *flagp の値は、この関数を呼ぶ前に .BR fegetexceptflag () 関数を呼び出して取得しておかなければならない (このとき、 .BR fegetexceptflag () の最後の引き数には、 .BR fesetexceptflag () に渡す .I excepts のすべてのビットを含む値を指定すること)。 .LP .\"O The .\"O .BR fetestexcept () .\"O function returns a word in which the bits are set that were .\"O set in the argument .\"O .I excepts .\"O and for which the corresponding exception is currently set. .BR fetestexcept () 関数は、 .I excepts 引き数でセットされているビットのうち、 現在設定されている例外に対応するビットが 1 になったワードを返す。 .\"O .SS Rounding mode .SS 丸めモード .\"O The rounding mode determines how the result of floating-point operations .\"O is treated when the result cannot be exactly represented in the significand. .\"O Various rounding modes may be provided: .\"O round to nearest (the default), .\"O round up (toward positive infinity), .\"O round down (toward negative infinity), and .\"O round toward zero. 丸めモードは、結果が仮数部だけで正確に表現できない際に、 浮動小数点操作の結果をどのように扱うかを決めるものである。 さまざまな丸めモードを提供することができる: 最も近い値に丸める (デフォルト)、 (正の無限大に向かって) 大きくなる方向に丸める、 (負の無限大に向かって) 小さくなる方向に丸める、 0 に向けて丸める、である。 .\"O Each of the macros .\"O .BR FE_TONEAREST , .\"O .BR FE_UPWARD , .\"O .BR FE_DOWNWARD , .\"O and .\"O .BR FE_TOWARDZERO .\"O is defined when the implementation supports getting and setting .\"O the corresponding rounding direction. .BR FE_TONEAREST , .BR FE_UPWARD , .BR FE_DOWNWARD , .BR FE_TOWARDZERO の各マクロは、それぞれ対応する丸めの方向を 実装がサポートしている場合に定義される。 .LP .\"O The .\"O .BR fegetround () .\"O function returns the macro corresponding to the current .\"O rounding mode. .BR fegetround () 関数は現在の丸めモードに対応するマクロを返す。 .LP .\"O The .\"O .BR fesetround () .\"O function sets the rounding mode as specified by its argument .\"O and returns zero when it was successful. .BR fesetround () 関数は丸めモードを引き数に与えられた値にし、 成功したらゼロを返す。 .\"O C99 and POSIX.1-2008 specify an identifier, .\"O .BR FLT_ROUNDS , .\"O defined in .\"O .IR , .\"O which indicates the implementation-defined rounding .\"O behavior for floating-point addition. .\"O This identifier has one of the following values: C99 と POSIX.1-2008 では .B FLT_ROUNDS という識別子が規定されており、 .I で定義されている。この識別子は 浮動小数点数の加算についての実装定義された丸め動作を表し、 以下のいずれかの値を持つ。 .IP \-1 .\"O The rounding mode is not determinable. 丸めモードは決められていない。 .IP 0 .\"O Rounding is toward 0. 0 に向けて丸める。 .IP 1 .\"O Rounding is toward nearest number. 最も近い数に丸める。 .IP 2 .\"O Rounding is toward positive infinity. 正の無限大に向けて丸める。 .IP 3 .\"O Rounding is toward negative infinity. 負の無限大に向けて丸める。 .PP .\"O Other values represent machine-dependent, nonstandard rounding modes. 他の値はマシン依存であり、標準的ではない丸めモードである。 .PP .\"O The value of .\"O .BR FLT_ROUNDS .\"O should reflect the current rounding mode as set by .\"O .BR fesetround () .\"O (but see BUGS). .BR FLT_ROUNDS の値には、 .BR fesetround () で設定された現在の丸めモードが反映されるべきである (但し、「バグ」の節を参照)。 .\"O .SS "Floating-point environment" .SS 浮動小数点関連の環境 .\"O The entire floating-point environment, including .\"O control modes and status flags, can be handled .\"O as one opaque object, of type .\"O .IR fenv_t . .\"O The default environment is denoted by .\"O .B FE_DFL_ENV .\"O (of type .\"O .IR "const fenv_t *" ). 浮動小数点関連の環境の全体は、 制御モードや状態フラグも含め、 .I fenv_t 型の内部オブジェクト一つで取り扱うことができる。 デフォルトの環境は、 .RI ( "const fenv_t *" 型の) .B FE_DFL_ENV で示されるものである。 .\"O This is the environment setup at program start and it is defined by .\"O ISO C to have round to nearest, all exceptions cleared and a nonstop .\"O (continue on exceptions) mode. これはプログラムの開始時に構築される環境であり、 ISO C では、丸めモードを最も近い値への丸め .RB ( FE_TONEAREST ) に設定し、すべての例外をクリアし、不停止 (nonstop) (例外が起きても継続する) モードとするように規定されている。 .LP .\"O The .\"O .BR fegetenv () .\"O function saves the current floating-point environment in the object .\"O .IR *envp . .BR fegetenv () 関数は、現在の浮動小数点環境を、オブジェクト .I *envp に保存する。 .LP .\"O The .\"O .BR feholdexcept () .\"O function does the same, then clears all exception flags, .\"O and sets a nonstop (continue on exceptions) mode, .\"O if available. .\"O It returns zero when successful. .BR feholdexcept () 関数も同じ動作を行い、 さらに可能であれば、全ての例外フラグをクリアし、 nonstop (例外時にも実行を継続) モードに設定する。 .LP .\"O The .\"O .BR fesetenv () .\"O function restores the floating-point environment from .\"O the object .\"O .IR *envp . .\"O This object must be known to be valid, for example, the result of a call to .\"O .BR fegetenv () .\"O or .\"O .BR feholdexcept () .\"O or equal to .\"O .BR FE_DFL_ENV . .\"O This call does not raise exceptions. .BR fesetenv () 関数は、浮動小数点環境を、オブジェクト .I *envp から取り出した値に戻す。 このオブジェクトは、有効であることが事前に分かっていなければならない。 例えば、 .BR fegetenv () や .BR feholdexcept () を呼び出した結果であるとか、 .B FE_DFL_ENV に等しいとかでなければならない。 この関数の呼び出しは例外を発生しない。 .LP .\"O The .\"O .BR feupdateenv () .\"O function installs the floating-point environment represented by .\"O the object .\"O .IR *envp , .\"O except that currently raised exceptions are not cleared. .\"O After calling this function, the raised exceptions will be a bitwise OR .\"O of those previously set with those in .\"O .IR *envp . .\"O As before, the object .\"O .I *envp .\"O must be known to be valid. .BR feupdateenv () 関数は、オブジェクト .I *envp が表現する浮動小数点環境をインストールする。 ただし、現在発生している例外はクリアされない。 この関数を呼んだ後に立っている例外は、 関数を呼ぶ前の値と .I *envp の値とのビットごとの OR を取ったものになる。 上記と同様に、オブジェクト .I *envp は、事前に有効であることが分かっていなければならない。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O These functions return zero on success and nonzero if an error occurred. .\"O .\" Earlier seven of these functions were listed as returning void. .\"O .\" This was corrected in Corrigendum 1 (ISO/IEC 9899:1999/Cor.1:2001(E)) .\"O .\" of the C99 Standard. これらの関数は、成功の場合 0 を返し、エラーが発生すると 0 以外を返す。 .\" 以前は、これらの関数のうち 7つは void を返すものと書かれていた。 .\" これは C99 標準の Corrigendum 1 (ISO/IEC 9899:1999/Cor.1:2001(E)) .\" で修正された。 .\"O .SH VERSIONS .SH バージョン .\"O These functions first appeared in glibc in version 2.1. これらの関数は glibc バージョン 2.1 で初めて登場した。 .\"O .SH "CONFORMING TO" .SH 準拠 IEC 60559 (IEC 559:1989), ANSI/IEEE 854, C99, POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O .SS Glibc Notes .SS glibc での注意 .\"O If possible, the GNU C Library defines a macro .\"O .B FE_NOMASK_ENV .\"O which represents an environment where every exception raised causes a .\"O trap to occur. .\"O You can test for this macro using .\"O .BR #ifdef . .\"O It is only defined if .\"O .B _GNU_SOURCE .\"O is defined. 可能な場合には、GNU C Library はマクロ .B FE_NOMASK_ENV を定義する。このマクロはすべての例外でトラップが生じるような環境を表す。 .B #ifdef を使ってこのマクロをテストできる。これは .B _GNU_SOURCE が定義されている場合に限って定義される。 .\"O The C99 standard does not define a way to set individual bits in the .\"O floating-point mask, for example, to trap on specific flags. .\"O glibc 2.2 supports the functions .\"O .BR feenableexcept () .\"O and .\"O .BR fedisableexcept () .\"O to set individual floating-point traps, and .\"O .BR fegetexcept () .\"O to query the state. C99 標準は浮動小数点マスク (例えば特定のフラグでのトラップなど) の各ビットの設定方法については定義していない。 glibc 2.2 は .BR feenableexcept () 関数と .BR fedisableexcept () 関数をサポートしており、 各々の浮動小数点トラップを設定できるようになっている。 また .BR fegetexcept () によって状態の問い合わせもできるようになっている。 .sp .nf .B "#define _GNU_SOURCE" .br .B "#include " .sp .BI "int feenableexcept(int " excepts ); .br .BI "int fedisableexcept(int " excepts ); .br .B "int fegetexcept(void);" .br .fi .LP .\"O The .\"O .BR feenableexcept () .\"O and .\"O .BR fedisableexcept () .\"O functions enable (disable) traps for each of the exceptions represented by .\"O .I excepts .\"O and return the previous set of enabled exceptions when successful, .\"O and \-1 otherwise. .\"O The .\"O .BR fegetexcept () .\"O function returns the set of all currently enabled exceptions. .BR feenebleexcept () 関数と .BR fedisableexcept () 関数は .I excepts によって表現される各例外のトラップを有効 (無効) にする。 成功した場合は直前に有効になっていた例外のセットを返す。 失敗した場合は \-1 を返す。 .BR fegetexcept () 関数は現在有効になっている例外全てからなるセットを返す。 .\"O .SH BUGS .SH バグ .\"O C99 specifies that the value of .\"O .B FLT_ROUNDS .\"O should reflect changes to the current rounding mode, as set by .\"O .BR fesetround (). C99 の規定では、 .BR FLT_ROUNDS の値には .BR fesetround () で設定された現在の丸めモードが反映されるべきであるとされている。 .\"O Currently, 現在のところ、 .\" Aug 08, glibc 2.8 .\"O this does not occur: .\"O .B FLT_ROUNDS .\"O always has the value 1. このようになっておらず、 .B FLT_ROUNDS は常に値 1 となる。 .\" See http://gcc.gnu.org/ml/gcc/2002-02/msg01535.html .\"O .SH "SEE ALSO" .SH 関連項目 .BR feature_test_macros (7), .BR math_error (7)