1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
23 .\" 2000-08-14 added GNU additions from Andreas Jaeger
24 .\" 2000-12-05 some changes inspired by acahalan's remarks
26 .\" Japanese Version Copyright (c) 2000-2001 NAKANO Takeo
27 .\" and Copyright (c) 2008 Akihiro MOTOKI.
28 .\" Translated 2001-02-08, NAKANO Takeo <nakano@apm.seikei.ac.jp>
29 .\" Updated 2003-10-15, Kentaro Shirakata <argrath@ub32.org>
30 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
31 .\" Updated 2008-09-16, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
33 .\"WORD: (floating-point) exception (浮動小数点) 例外
37 .TH FENV 3 2010-10-31 "Linux" "Linux Programmer's Manual"
40 .\"O feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag,
41 .\"O fetestexcept, fegetenv, fegetround, feholdexcept, fesetround,
42 .\"O fesetenv, feupdateenv, feenableexcept, fedisableexcept,
43 .\"O fegetexcept \- floating-point rounding and exception handling
44 feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag,
45 fetestexcept, fegetenv, fegetround, feholdexcept, fesetround,
46 fesetenv, feupdateenv, feenableexcept, fedisableexcept,
47 fegetexcept \- 浮動小数点の丸めと例外の取り扱い
53 .BI "int feclearexcept(int " excepts );
55 .BI "int fegetexceptflag(fexcept_t *" flagp ", int " excepts );
57 .BI "int feraiseexcept(int " excepts );
59 .BI "int fesetexceptflag(const fexcept_t *" flagp ", int " excepts );
61 .BI "int fetestexcept(int " excepts );
63 .B "int fegetround(void);"
65 .BI "int fesetround(int " rounding_mode );
67 .BI "int fegetenv(fenv_t *" envp );
69 .BI "int feholdexcept(fenv_t *" envp );
71 .BI "int fesetenv(const fenv_t *" envp );
73 .BI "int feupdateenv(const fenv_t *" envp );
76 .\"O Link with \fI\-lm\fP.
80 .\"O These eleven functions were defined in C99, and describe the handling
81 .\"O of floating-point rounding and exceptions (overflow, zero-divide etc.).
82 これらの 11 個の関数は C99 で定義されており、
83 浮動小数点の丸めと例外 (オーバーフロー、ゼロによる除算など)
88 .\"O .I divide-by-zero
89 .\"O exception occurs when an operation on finite numbers
90 .\"O produces infinity as exact answer.
97 .\"O exception occurs when a result has to be represented as a
98 .\"O floating-point number, but has (much) larger absolute value than the
99 .\"O largest (finite) floating-point number that is representable.
101 例外は、結果が浮動小数点数値で表記されなければならないのに、
102 その絶対値が表現可能な浮動小数点数の (有限の) 最大値よりも
103 (ずっと) 大きくなってしまうような場合に起こる。
107 .\"O exception occurs when a result has to be represented as a
108 .\"O floating-point number, but has smaller absolute value than the smallest
109 .\"O positive normalized floating-point number (and would lose much accuracy
110 .\"O when represented as a denormalized number).
112 例外は、結果が浮動小数点数値で表記されなければならないのに、
113 その絶対値が正の正規化浮動小数点数の最小値よりも
115 (そして 非正規化数で表現した場合に非常に精度を失ってしまう)
120 .\"O exception occurs when the rounded result of an operation
121 .\"O is not equal to the infinite precision result.
122 .\"O It may occur whenever
129 無限精度の結果と異なるような場合に起こる。
133 例外が起きたときには、常にこの例外も起こる。
137 .\"O exception occurs when there is no well-defined result
138 .\"O for an operation, as for 0/0 or infinity \- infinity or sqrt(\-1).
140 例外は、演算結果がうまく定義できない結果を生じるような場合に起こる。
141 例えば 0/0、無限大 \- 無限大、sqrt(\-1) など。
142 .\"O .SS "Exception handling"
144 .\"O Exceptions are represented in two ways: as a single bit
145 .\"O (exception present/absent), and these bits correspond in some
146 .\"O implementation-defined way with bit positions in an integer,
147 .\"O and also as an opaque structure that may contain more information
148 .\"O about the exception (perhaps the code address where it occurred).
150 ひとつは、単一のビットで (例外があったかなかったかを) 表す方法で、
151 これらのビットは整数のあるビット位置に対応し、ビットの対応付けは
152 実装依存である。もう一つは、内部構造体を使って表す方法で、
154 (例えば例外が起こったコードのアドレスなど) が含まれる。
156 .\"O Each of the macros
157 .\"O .BR FE_DIVBYZERO ,
158 .\"O .BR FE_INEXACT ,
159 .\"O .BR FE_INVALID ,
160 .\"O .BR FE_OVERFLOW ,
162 .\"O is defined when the implementation supports handling
163 .\"O of the corresponding exception, and if so then
164 .\"O defines the corresponding bit(s), so that one can call
165 .\"O exception handling functions, for example, using the integer argument
166 .\"O .BR FE_OVERFLOW | FE_UNDERFLOW .
167 .\"O Other exceptions may be supported.
169 .\"O .B FE_ALL_EXCEPT
170 .\"O is the bitwise OR of all bits corresponding to supported exceptions.
176 の各マクロは、それぞれ対応する例外の処理を
178 このとき対応するビットをそれぞれ定義することになるので、
180 .BR FE_OVERFLOW | FE_UNDERFLOW
181 という整数の引き数を用いて行うことができる。
182 他の例外もサポートされているかもしれない。
184 マクロは、サポートされている例外に対応するビットが全てセットされている
185 (サポートされている例外全ての論理和である)。
188 .\"O .BR feclearexcept ()
189 .\"O function clears the supported exceptions represented by the bits
190 .\"O in its argument.
195 (処理は実装でサポートされている例外についてのみ行われる)。
198 .\"O .BR fegetexceptflag ()
199 .\"O function stores a representation of the state of the exception flags
200 .\"O represented by the argument
202 .\"O in the opaque object
204 .BR fegetexceptflag ()
212 .\"O .BR feraiseexcept ()
213 .\"O function raises the supported exceptions represented by the bits in
222 .\"O .BR fesetexceptflag ()
223 .\"O function sets the complete status for the exceptions represented by
227 .\"O This value must have been obtained by an earlier call of
228 .\"O .BR fegetexceptflag ()
229 .\"O with a last argument that contained all bits in
231 .BR fesetexceptflag ()
239 .BR fegetexceptflag ()
240 関数を呼び出して取得しておかなければならない
242 .BR fegetexceptflag ()
244 .BR fesetexceptflag ()
247 のすべてのビットを含む値を指定すること)。
250 .\"O .BR fetestexcept ()
251 .\"O function returns a word in which the bits are set that were
252 .\"O set in the argument
254 .\"O and for which the corresponding exception is currently set.
259 現在設定されている例外に対応するビットが 1 になったワードを返す。
260 .\"O .SS Rounding mode
262 .\"O The rounding mode determines how the result of floating-point operations
263 .\"O is treated when the result cannot be exactly represented in the significand.
264 .\"O Various rounding modes may be provided:
265 .\"O round to nearest (the default),
266 .\"O round up (toward positive infinity),
267 .\"O round down (toward negative infinity), and
268 .\"O round toward zero.
269 丸めモードは、結果が仮数部だけで正確に表現できない際に、
270 浮動小数点操作の結果をどのように扱うかを決めるものである。
271 さまざまな丸めモードを提供することができる:
273 (正の無限大に向かって) 大きくなる方向に丸める、
274 (負の無限大に向かって) 小さくなる方向に丸める、
277 .\"O Each of the macros
278 .\"O .BR FE_TONEAREST ,
280 .\"O .BR FE_DOWNWARD ,
282 .\"O .BR FE_TOWARDZERO
283 .\"O is defined when the implementation supports getting and setting
284 .\"O the corresponding rounding direction.
289 の各マクロは、それぞれ対応する丸めの方向を
293 .\"O .BR fegetround ()
294 .\"O function returns the macro corresponding to the current
297 関数は現在の丸めモードに対応するマクロを返す。
300 .\"O .BR fesetround ()
301 .\"O function sets the rounding mode as specified by its argument
302 .\"O and returns zero when it was successful.
304 関数は丸めモードを引き数に与えられた値にし、
307 .\"O C99 and POSIX.1-2008 specify an identifier,
308 .\"O .BR FLT_ROUNDS ,
311 .\"O which indicates the implementation-defined rounding
312 .\"O behavior for floating-point addition.
313 .\"O This identifier has one of the following values:
314 C99 と POSIX.1-2008 では
319 浮動小数点数の加算についての実装定義された丸め動作を表し、
322 .\"O The rounding mode is not determinable.
325 .\"O Rounding is toward 0.
328 .\"O Rounding is toward nearest number.
331 .\"O Rounding is toward positive infinity.
334 .\"O Rounding is toward negative infinity.
337 .\"O Other values represent machine-dependent, nonstandard rounding modes.
338 他の値はマシン依存であり、標準的ではない丸めモードである。
342 .\"O should reflect the current rounding mode as set by
343 .\"O .BR fesetround ()
348 で設定された現在の丸めモードが反映されるべきである
350 .\"O .SS "Floating-point environment"
352 .\"O The entire floating-point environment, including
353 .\"O control modes and status flags, can be handled
354 .\"O as one opaque object, of type
356 .\"O The default environment is denoted by
359 .\"O .IR "const fenv_t *" ).
363 型の内部オブジェクト一つで取り扱うことができる。
365 .RI ( "const fenv_t *"
369 .\"O This is the environment setup at program start and it is defined by
370 .\"O ISO C to have round to nearest, all exceptions cleared and a nonstop
371 .\"O (continue on exceptions) mode.
372 これはプログラムの開始時に構築される環境であり、
373 ISO C では、丸めモードを最も近い値への丸め
375 に設定し、すべての例外をクリアし、不停止 (nonstop)
376 (例外が起きても継続する) モードとするように規定されている。
380 .\"O function saves the current floating-point environment in the object
383 関数は、現在の浮動小数点環境を、オブジェクト
388 .\"O .BR feholdexcept ()
389 .\"O function does the same, then clears all exception flags,
390 .\"O and sets a nonstop (continue on exceptions) mode,
392 .\"O It returns zero when successful.
395 さらに可能であれば、全ての例外フラグをクリアし、
396 nonstop (例外時にも実行を継続) モードに設定する。
400 .\"O function restores the floating-point environment from
403 .\"O This object must be known to be valid, for example, the result of a call to
406 .\"O .BR feholdexcept ()
408 .\"O .BR FE_DFL_ENV .
409 .\"O This call does not raise exceptions.
414 このオブジェクトは、有効であることが事前に分かっていなければならない。
425 .\"O .BR feupdateenv ()
426 .\"O function installs the floating-point environment represented by
429 .\"O except that currently raised exceptions are not cleared.
430 .\"O After calling this function, the raised exceptions will be a bitwise OR
431 .\"O of those previously set with those in
433 .\"O As before, the object
435 .\"O must be known to be valid.
439 が表現する浮動小数点環境をインストールする。
440 ただし、現在発生している例外はクリアされない。
444 の値とのビットごとの OR を取ったものになる。
447 は、事前に有効であることが分かっていなければならない。
448 .\"O .SH "RETURN VALUE"
450 .\"O These functions return zero on success and nonzero if an error occurred.
451 .\"O .\" Earlier seven of these functions were listed as returning void.
452 .\"O .\" This was corrected in Corrigendum 1 (ISO/IEC 9899:1999/Cor.1:2001(E))
453 .\"O .\" of the C99 Standard.
454 これらの関数は、成功の場合 0 を返し、エラーが発生すると 0 以外を返す。
455 .\" 以前は、これらの関数のうち 7つは void を返すものと書かれていた。
456 .\" これは C99 標準の Corrigendum 1 (ISO/IEC 9899:1999/Cor.1:2001(E))
460 .\"O These functions first appeared in glibc in version 2.1.
461 これらの関数は glibc バージョン 2.1 で初めて登場した。
462 .\"O .SH "CONFORMING TO"
464 IEC 60559 (IEC 559:1989), ANSI/IEEE 854, C99, POSIX.1-2001.
469 .\"O If possible, the GNU C Library defines a macro
470 .\"O .B FE_NOMASK_ENV
471 .\"O which represents an environment where every exception raised causes a
473 .\"O You can test for this macro using
475 .\"O It is only defined if
478 可能な場合には、GNU C Library はマクロ
480 を定義する。このマクロはすべての例外でトラップが生じるような環境を表す。
485 .\"O The C99 standard does not define a way to set individual bits in the
486 .\"O floating-point mask, for example, to trap on specific flags.
487 .\"O Since version 2.2, glibc supports the functions
488 .\"O .BR feenableexcept ()
490 .\"O .BR fedisableexcept ()
491 .\"O to set individual floating-point traps, and
492 .\"O .BR fegetexcept ()
493 .\"O to query the state.
494 C99 標準は浮動小数点マスク (例えば特定のフラグでのトラップなど)
495 の各ビットの設定方法については定義していない。
496 バージョン 2.2 以降の glibc は、
497 .BR feenableexcept ()
499 .BR fedisableexcept ()
501 各々の浮動小数点トラップを設定できるようになっている。
504 によって状態の問い合わせもできるようになっている。
507 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
508 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
509 .B "#define _GNU_SOURCE"
511 .B "#include <fenv.h>"
513 .BI "int feenableexcept(int " excepts );
515 .BI "int fedisableexcept(int " excepts );
517 .B "int fegetexcept(void);"
522 .\"O .BR feenableexcept ()
524 .\"O .BR fedisableexcept ()
525 .\"O functions enable (disable) traps for each of the exceptions represented by
527 .\"O and return the previous set of enabled exceptions when successful,
528 .\"O and \-1 otherwise.
530 .\"O .BR fegetexcept ()
531 .\"O function returns the set of all currently enabled exceptions.
532 .BR feenableexcept ()
534 .BR fedisableexcept ()
537 によって表現される各例外のトラップを有効 (無効) にする。
538 成功した場合は直前に有効になっていた例外のセットを返す。
541 関数は現在有効になっている例外全てからなるセットを返す。
544 .\"O C99 specifies that the value of
546 .\"O should reflect changes to the current rounding mode, as set by
547 .\"O .BR fesetround ().
552 で設定された現在の丸めモードが反映されるべきであるとされている。
555 .\" Aug 08, glibc 2.8
556 .\"O this does not occur:
558 .\"O always has the value 1.
562 .\" See http://gcc.gnu.org/ml/gcc/2002-02/msg01535.html