1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
25 .\" all rights reserved.
26 .\" Translated 2008-08-17, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.07
28 .\"WORD: significand 仮数部
29 .\"WORD: domain error 領域エラー
30 .\"WORD: pole error 極エラー
31 .\"WORD: range error 範囲エラー
33 .TH MATH_ERROR 7 2008-08-11 "Linux" "Linux Programmer's Manual"
36 .\"O math_error \- detecting errors from mathematical functions
37 math_error \- 数学関数からのエラーの検出
47 .\"O When an error occurs,
48 .\"O most library functions indicate this fact by returning a special value
49 .\"O (e.g., \-1 or NULL).
50 .\"O Because they typically return a floating-point number,
51 .\"O the mathematical functions declared in
53 .\"O indicate an error using other mechanisms.
54 .\"O There are two error-reporting mechanisms:
55 .\"O the older one sets
57 .\"O the newer one uses the floating-point exception mechanism (the use of
58 .\"O .BR feclearexcept (3)
60 .\"O .BR fetestexcept (3),
61 .\"O as outlined below)
64 エラーが発生すると、ほとんどのライブラリ関数は (\-1 や NULL などの)
67 で宣言されている数学関数は、通常は浮動小数点値を返すので、
75 .RB ( feclearexcept (3)
78 を使用する。これらについては以下で概要を説明している。)
80 .\"O A portable program that needs to check for an error from a mathematical
81 .\"O function should set
83 .\"O to zero, and make the following call
84 移植性が必要なプログラムで、数学関数からのエラーを確認する必要がある場合には、
87 を 0 に設定し、以下を呼び出すべきである。
91 feclearexcept(FE_ALL_EXCEPT);
95 .\"O before calling a mathematical function.
96 .\"Omotoki: 対応する訳は feclearexcept の引用の前にある。
98 .\"O Upon return from the mathematical function, if
100 .\"O is nonzero, or the following call (see
105 が 0 以外か、以下の呼び出しが 0 以外を返した場合
111 fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW |
118 .\" FE_INVALID = 0x01,
119 .\" __FE_DENORM = 0x02,
120 .\" FE_DIVBYZERO = 0x04,
121 .\" FE_OVERFLOW = 0x08,
122 .\" FE_UNDERFLOW = 0x10,
123 .\" FE_INEXACT = 0x20
125 .\"O then an error occurred in the mathematical function.
126 .\"Omotoki: 対応する訳は fetestexcept の引用の前にある。
128 .\"O The error conditions that can occur for mathematical functions
129 .\"O are described below.
130 数学関数で発生するエラー条件については以下で説明する。
131 .\"O .SS Domain Error
132 .SS 領域エラー (domain error)
135 .\"O occurs when a mathematical function is supplied with an argument whose
136 .\"O value falls outside the domain for which the function
137 .\"O is defined (e.g., giving a negative argument to
139 .\"O When a domain error occurs,
140 .\"O math functions commonly return a NaN
141 .\"O (though some functions return a different value in this case);
145 .\"O and an "invalid"
146 .\"O .RB ( FE_INVALID )
147 .\"O floating-point exception is raised.
149 が発生するのは、数学関数に渡された引き数の値がその関数が定義されている
164 .SS 極エラー (pole error)
167 .\"O occurs when the mathematical result of a function is an exact infinity
168 .\"O (e.g., the logarithm of 0 is negative infinity).
169 .\"O When a pole error occurs,
170 .\"O the function returns the (signed) value
175 .\"O depending on whether the function result type is
179 .\"O .IR "long double" .
180 .\"O The sign of the result is that which is mathematically correct for
183 が発生するのは、関数の数学的な結果が無限大そのものとなる場合である
186 極エラーが発生すると、その関数の返り値は (符号付きの)
190 のいずれかとなる (前記の値のうちどれが返るかは関数の返り値の型により決まり、
196 結果の符号は、その関数の数学的な定義から決定される。
200 .\"O and a "divide-by-zero"
201 .\"O .RB ( FE_DIVBYZERO )
202 .\"O floating-point exception is raised.
206 に設定され、「0 による除算 (divide-by-zero)」
211 .SS 範囲エラー (range エラー)
214 .\"O occurs when the magnitude of the function result means that it
215 .\"O cannot be represented in the result type of the function.
216 .\"O The return value of the function depends on whether the range error
217 .\"O was an overflow or an underflow.
219 が発生するのは、関数の結果の値がその関数の返り値の型では表現できない場合
220 である。関数の返り値は、範囲エラーがオーバーフローであったかアンダーフロー
223 .\"O A floating result
225 .\"O if the result is finite,
226 .\"O but is too large to represented in the result type.
227 .\"O When an overflow occurs,
228 .\"O the function returns the value
233 .\"O depending on whether the function result type is
237 .\"O .IR "long double" .
241 .\"O and an "overflow"
242 .\"O .RB ( FE_OVERFLOW )
243 .\"O floating-point exception is raised.
244 浮動小数点のオーバーフローは、結果が有限だが、大き過ぎて
245 結果を返す型では表現できない場合に発生する。
251 のいずれかを返す (前記の値のうちどれが返るかは関数の返り値の型により決まり、
260 に設定され、「オーバーフロー (overflow)」
265 .\"O A floating result
267 .\"O if the result is too small to be represented in the result type.
268 .\"O If an underflow occurs,
269 .\"O a mathematical function typically returns 0.0
270 .\"O (C99 says a function shall return "an implementation-defined value
271 .\"O whose magnitude is no greater than the smallest normalized
272 .\"O positive number in the specified type").
274 結果が小さ過ぎて、結果を返す型では表現できない場合に発生する。
275 アンダーフローが発生すると、数学関数は通常は 0.0 を返す
276 (C99 では、指定された型において最小の正規化された正の値より大きくない
277 値を持つ実装定義 (implementation-defined) の値を返す、となっている)。
281 .\"O and an "overflow"
282 .\"O .RB ( FE_UNDERFLOW )
283 .\"O floating-point exception may be raised.
287 に設定され、「アンダーフロー」浮動小数点例外
291 .\"O Some functions deliver a range error if the supplied argument value,
292 .\"O or the correct function result, would be
294 .\"O A subnormal value is one that is nonzero,
295 .\"O but with a magnitude that is so small that
296 .\"O it can't be presented in normalized form
297 .\"O (i.e., with a 1 in the most significant bit of the significand).
298 .\"O The representation of a subnormal number will contain one
299 .\"O or more leading zeros in the significand.
300 いくつかの関数では、渡された引き数の値や、正しい関数の結果が
303 subnormal な値とは、0 ではないが、その値が小さすぎて
304 (仮数部の最上位ビットが 1 となる) 標準形では表現できないような値である。
305 subnormal な値の表現では、仮数部の上位側のビットに 1 個以上の 0 が
310 .\"O .I math_errhandling
311 .\"O identifier specified by C99 and POSIX.1-2001 is not supported by glibc.
312 C99 と POSIX.1-2001 で規定されている
314 識別子は glibc ではサポートされていない。
315 .\" See CONFORMANCE in the glibc 2.8 (and earlier) source.
316 .\"O This identifier is supposed to indicate which of the two
317 .\"O error-notification mechanisms
319 .\"O exceptions retrievable via
320 .\"O .BR fettestexcept (3))
326 経由で取得できる例外) のうちどちらが使用されているかを通知
328 .\"O The standards require that at least one be in use,
329 .\"O but permit both to be available.
330 .\"O The current (version 2.8) situation under glibc is messy.
331 .\"O Most (but not all) functions raise exceptions on errors.
334 .\"O A few functions set
336 .\"O but don't raise an exception.
337 .\"O A very few functions do neither.
338 .\"O See the individual manual pages for details.
339 標準では、少なくとも一つは使用されることが要求されているが、
340 両方とも利用可能であってもよいとされている。
341 glibc での現在の (バージョン 2.8 での) 状況はかなり混乱している。
342 ほとんどの関数 (ただし全部ではない) はエラー時に例外を上げる。
347 を設定するが、例外を上げない関数も少しだけ存在する。
348 どちらも行わない関数もごく少数だが存在する。
349 詳細については個々のマニュアルページを参照のこと。
351 .\"O To avoid the complexities of using
354 .\"O .BR fetestexcept (3)
355 .\"O for error checking,
356 .\"O it is often advised that one should instead check for bad argument
357 .\"O values before each call.
361 の両方を使ってエラーチェックを行うことで複雑になるのを避けるため、
362 多くの場合、関数呼び出しを行う前に不正な引き数かのチェックを行う
364 .\" http://www.securecoding.cert.org/confluence/display/seccode/FLP32-C.+Prevent+or+detect+domain+and+range+errors+in+math+functions
365 .\"O For example, the following code ensures that
367 .\"O argument is not a NaN and is not zero (a pole error) or
368 .\"O less than zero (a domain error):
371 の引き数が NaN でも (極エラーとなる) 0 でも (領域エラーとなる) 0 未満
378 if (isnan(x) || islessequal(x, 0)) {
379 /* Deal with NaN / pole error / domain error */
386 .\"O The discussion on this page does not apply to the complex
387 .\"O mathematical functions (i.e., those declared by
388 .\"O .IR <complex.h> ),
389 .\"O which in general are not required to return errors by C99
390 .\"O and POSIX.1-2001.
393 で宣言されている) 複素数関数にはあてはまらない。
394 一般に、C99 や POSIX.1-2001 ではこれらの関数がエラーを返すことを
399 .\"O .I "-fno-math-errno"
400 .\"O option causes the executable to employ implementations of some
401 .\"O mathematical functions that are faster than the standard
402 .\"O implementations, but do not set
407 .\"O .I "-ffast-math"
408 .\"O option also enables
409 .\"O .IR "-fno-math-errno" .)
410 .\"O An error can still be tested for using
411 .\"O .BR fetestexcept (3).
415 オプションを使うと、実行ファイルで、標準の実装よりも高速な数学関数の