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 ¤Ê¤É¤Î)
65 ÆÃÊ̤ÊÃͤòÊÖ¤¹¤³¤È¤Ç¥¨¥é¡¼¤òÄÌÃΤ¹¤ë¡£
67 ¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë¿ô³Ø´Ø¿ô¤Ï¡¢Ä̾ï¤ÏÉâÆ°¾®¿ôÅÀÃͤòÊÖ¤¹¤Î¤Ç¡¢
68 ¾¤Îµ¡¹½¤ò»È¤Ã¤Æ¥¨¥é¡¼¤òÄÌÃΤ¹¤ë¡£
69 ¥¨¥é¡¼ÄÌÃε¡¹½¤Ï 2 ¼ïÎढ¤ê¡¢
72 ¤òÀßÄꤹ¤ë¤ä¤êÊý¤Ç¤¢¤ê¡¢¿·¤·¤¤¤â¤Î¤¬
74 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ëÉâÆ°¾®¿ôÅÀÎã³°µ¡¹½¤Ç¤¢¤ë¡£
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 °Ü¿¢À¤¬É¬Í×¤Ê¥×¥í¥°¥é¥à¤Ç¡¢¿ô³Ø´Ø¿ô¤«¤é¤Î¥¨¥é¡¼¤ò³Îǧ¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢
85 ¿ô³Ø´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë
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
103 ¿ô³Ø´Ø¿ô¤«¤éÊ֤äƤ¤¿ºÝ¤Ë¡¢
105 ¤¬ 0 °Ê³°¤«¡¢°Ê²¼¤Î¸Æ¤Ó½Ð¤·¤¬ 0 °Ê³°¤òÊÖ¤·¤¿¾ì¹ç
107 »²¾È)¡¢¿ô³Ø´Ø¿ô¤Ç¥¨¥é¡¼¤¬È¯À¸¤·¤Æ¤¤¤ë¡£
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 ¤¬È¯À¸¤¹¤ë¤Î¤Ï¡¢¿ô³Ø´Ø¿ô¤ËÅϤµ¤ì¤¿°ú¤¿ô¤ÎÃͤ¬¤½¤Î´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë
150 Îΰè¤ËÆþ¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë (Î㤨¤Ð
152 ¤ËÉé¤Î°ú¤¿ô¤òÅϤ·¤¿¾ì¹ç)¡£
153 Îΰ襨¥é¡¼¤¬È¯À¸¤¹¤ë¤È¡¢
154 ¿ô³Ø´Ø¿ô¤ÏÉáÄÌ¤Ï NaN ¤òÊÖ¤·
155 (Ʊ¤¸¾õ¶·¤Ç°ã¤¦ÃͤòÊÖ¤¹´Ø¿ô¤â¤¢¤ë)¡¢
159 ¤òÀßÄꤷ¡¢¡Ö̵¸ú (invalid)¡×
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 ¤¬È¯À¸¤¹¤ë¤Î¤Ï¡¢´Ø¿ô¤Î¿ô³ØŪ¤Ê·ë²Ì¤¬Ìµ¸ÂÂ礽¤Î¤â¤Î¤È¤Ê¤ë¾ì¹ç¤Ç¤¢¤ë
185 0 ¤ÎÂпô¤ÏÉé¤Î̵¸ÂÂç¤Ç¤¢¤ë)¡£
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 ¤Ç¤¢¤ë¡£´Ø¿ô¤ÎÊÖ¤êÃͤϡ¢ÈÏ°Ï¥¨¥é¡¼¤¬¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Ç¤¢¤Ã¤¿¤«¥¢¥ó¥À¡¼¥Õ¥í¡¼
221 ¤Ç¤¢¤Ã¤¿¤«¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
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 ·ë²Ì¤òÊÖ¤¹·¿¤Ç¤Ïɽ¸½¤Ç¤¤Ê¤¤¾ì¹ç¤ËȯÀ¸¤¹¤ë¡£
246 ¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬È¯À¸¤¹¤ë¤È¡¢
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").
273 ÉâÆ°¾®¿ôÅÀ¤Î¥¢¥ó¥À¡¼¥Õ¥í¡¼¤Ï¡¢
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 ¤¤¤¯¤Ä¤«¤Î´Ø¿ô¤Ç¤Ï¡¢ÅϤµ¤ì¤¿°ú¤¿ô¤ÎÃͤ䡢Àµ¤·¤¤´Ø¿ô¤Î·ë²Ì¤¬
301 .I subnormal (ÈóÀµµ¬²½¿ô)
302 ¤Ë¤Ê¤ë¾ì¹ç¤ËÈÏ°Ï¥¨¥é¡¼¤ò¾å¤²¤ë¡£
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))
322 ¤³¤Î¼±Ê̻Ҥϡ¢2 ¤Ä¤Î¥¨¥é¡¼ÄÌÃε¡¹½
326 ·Ðͳ¤Ç¼èÆÀ¤Ç¤¤ëÎã³°) ¤Î¤¦¤Á¤É¤Á¤é¤¬»ÈÍѤµ¤ì¤Æ¤¤¤ë¤«¤òÄÌÃÎ
327 ¤¹¤ë¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
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 ¿¤¯¤Î¾ì¹ç¡¢´Ø¿ô¸Æ¤Ó½Ð¤·¤ò¹Ô¤¦Á°¤ËÉÔÀµ¤Ê°ú¤¿ô¤«¤Î¥Á¥§¥Ã¥¯¤ò¹Ô¤¦
363 ÊýË¡¤¬¿ä¾©¤µ¤ì¤Æ¤¤¤ë¡£
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):
369 Î㤨¤Ð¡¢°Ê²¼¤Î¥³¡¼¥É¤Ï¡¢
371 ¤Î°ú¤¿ô¤¬ NaN ¤Ç¤â (¶Ë¥¨¥é¡¼¤È¤Ê¤ë) 0 ¤Ç¤â (Îΰ襨¥é¡¼¤È¤Ê¤ë) 0 ̤Ëþ
372 ¤Ç¤â¤Ê¤¤¤³¤È¤òÊݾڤ¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
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.
391 ¤³¤Î¥Ú¡¼¥¸¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¤³¤È¤Ï¡¢
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 ¥ª¥×¥·¥ç¥ó¤ò»È¤¦¤È¡¢¼Â¹Ô¥Õ¥¡¥¤¥ë¤Ç¡¢É¸½à¤Î¼ÂÁõ¤è¤ê¤â¹â®¤Ê¿ô³Ø´Ø¿ô¤Î
416 ¼ÂÁõ¤¬»ÈÍѤµ¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¤¬¡¢
423 ¥ª¥×¥·¥ç¥ó¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤â
426 ¤³¤Î¥ª¥×¥·¥ç¥ó¤ò»ØÄꤷ¤¿¾ì¹ç¤Ç¤â¡¢
428 ¤ò»È¤Ã¤¿¥¨¥é¡¼¤Î¸¡ºº¤Ï²Äǽ¤Ç¤¢¤ë¡£