OSDN Git Service

(split) Apply minor changes from v3.32 to v3.35 in the upstream.
[linuxjm/LDP_man-pages.git] / draft / man7 / math_error.7
1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
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
27 .\" 
28 .\"WORD:        significand     ²¾¿ôÉô
29 .\"WORD:        domain error    Îΰ襨¥é¡¼
30 .\"WORD:        pole error      ¶Ë¥¨¥é¡¼
31 .\"WORD:        range error     ÈÏ°Ï¥¨¥é¡¼
32 .\" 
33 .TH MATH_ERROR 7 2008-08-11 "Linux" "Linux Programmer's Manual"
34 .\"O .SH NAME
35 .SH Ì¾Á°
36 .\"O math_error \- detecting errors from mathematical functions
37 math_error \- ¿ô³Ø´Ø¿ô¤«¤é¤Î¥¨¥é¡¼¤Î¸¡½Ð
38 .\"O .SH SYNOPSIS
39 .SH ½ñ¼°
40 .nf
41 .B #include <math.h>
42 .B #include <errno.h>
43 .B #include <fenv.h>
44 .fi
45 .\"O .SH DESCRIPTION
46 .SH ÀâÌÀ
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
52 .\"O .IR <math.h>
53 .\"O indicate an error using other mechanisms.
54 .\"O There are two error-reporting mechanisms:
55 .\"O the older one sets
56 .\"O .IR errno ;
57 .\"O the newer one uses the floating-point exception mechanism (the use of
58 .\"O .BR feclearexcept (3)
59 .\"O and
60 .\"O .BR fetestexcept (3),
61 .\"O as outlined below)
62 .\"O described in
63 .\"O .BR fenv (3).
64 ¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤È¡¢¤Û¤È¤ó¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï (\-1 ¤ä NULL ¤Ê¤É¤Î)
65 ÆÃÊ̤ÊÃͤòÊÖ¤¹¤³¤È¤Ç¥¨¥é¡¼¤òÄÌÃΤ¹¤ë¡£
66 .I <math.h>
67 ¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë¿ô³Ø´Ø¿ô¤Ï¡¢Ä̾ï¤ÏÉâÆ°¾®¿ôÅÀÃͤòÊÖ¤¹¤Î¤Ç¡¢
68 ¾¤Îµ¡¹½¤ò»È¤Ã¤Æ¥¨¥é¡¼¤òÄÌÃΤ¹¤ë¡£
69 ¥¨¥é¡¼ÄÌÃε¡¹½¤Ï 2 ¼ïÎढ¤ê¡¢
70 ¸Å¤¤¤â¤Î¤¬
71 .I errno
72 ¤òÀßÄꤹ¤ë¤ä¤êÊý¤Ç¤¢¤ê¡¢¿·¤·¤¤¤â¤Î¤¬
73 .BR fenv (3)
74 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ëÉâÆ°¾®¿ôÅÀÎã³°µ¡¹½¤Ç¤¢¤ë¡£
75 .RB ( feclearexcept (3)
76 ¤È
77 .BR fetestexcept (3)
78 ¤ò»ÈÍѤ¹¤ë¡£¤³¤ì¤é¤Ë¤Ä¤¤¤Æ¤Ï°Ê²¼¤Ç³µÍפòÀâÌÀ¤·¤Æ¤¤¤ë¡£)
79
80 .\"O A portable program that needs to check for an error from a mathematical
81 .\"O function should set
82 .\"O .I errno
83 .\"O to zero, and make the following call
84 °Ü¿¢À­¤¬É¬Í×¤Ê¥×¥í¥°¥é¥à¤Ç¡¢¿ô³Ø´Ø¿ô¤«¤é¤Î¥¨¥é¡¼¤ò³Îǧ¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢
85 ¿ô³Ø´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë
86 .I errno
87 ¤ò 0 ¤ËÀßÄꤷ¡¢°Ê²¼¤ò¸Æ¤Ó½Ð¤¹¤Ù¤­¤Ç¤¢¤ë¡£
88 .in +4n
89 .nf
90
91 feclearexcept(FE_ALL_EXCEPT);
92 .\"O 
93 .fi
94 .in
95 .\"O before calling a mathematical function.
96 .\"Omotoki: Âбþ¤¹¤ëÌõ¤Ï feclearexcept ¤Î°úÍѤÎÁ°¤Ë¤¢¤ë¡£
97
98 .\"O Upon return from the mathematical function, if
99 .\"O .I errno
100 .\"O is nonzero, or the following call (see
101 .\"O .BR fenv (3))
102 .\"O returns nonzero
103 ¿ô³Ø´Ø¿ô¤«¤éÊ֤äƤ­¤¿ºÝ¤Ë¡¢
104 .I errno
105 ¤¬ 0 °Ê³°¤«¡¢°Ê²¼¤Î¸Æ¤Ó½Ð¤·¤¬ 0 °Ê³°¤òÊÖ¤·¤¿¾ì¹ç
106 .RB ( fenv (3)
107 »²¾È)¡¢¿ô³Ø´Ø¿ô¤Ç¥¨¥é¡¼¤¬È¯À¸¤·¤Æ¤¤¤ë¡£
108 .in +4n
109 .nf
110
111 fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW |
112              FE_UNDERFLOW);
113 .\"O 
114 .fi
115 .in
116 .\" enum
117 .\" {
118 .\" FE_INVALID = 0x01,
119 .\" __FE_DENORM = 0x02,
120 .\" FE_DIVBYZERO = 0x04,
121 .\" FE_OVERFLOW = 0x08,
122 .\" FE_UNDERFLOW = 0x10,
123 .\" FE_INEXACT = 0x20
124 .\" };
125 .\"O then an error occurred in the mathematical function.
126 .\"Omotoki: Âбþ¤¹¤ëÌõ¤Ï fetestexcept ¤Î°úÍѤÎÁ°¤Ë¤¢¤ë¡£
127
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)
133 .\"O A
134 .\"O .I 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
138 .\"O .BR log (3)).
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);
142 .\"O .I errno
143 .\"O is set to
144 .\"O .BR EDOM ,
145 .\"O and an "invalid"
146 .\"O .RB ( FE_INVALID )
147 .\"O floating-point exception is raised.
148 .I Îΰ襨¥é¡¼
149 ¤¬È¯À¸¤¹¤ë¤Î¤Ï¡¢¿ô³Ø´Ø¿ô¤ËÅϤµ¤ì¤¿°ú¤­¿ô¤ÎÃͤ¬¤½¤Î´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë
150 Îΰè¤ËÆþ¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë (Î㤨¤Ð
151 .BR log (3)
152 ¤ËÉé¤Î°ú¤­¿ô¤òÅϤ·¤¿¾ì¹ç)¡£
153 Îΰ襨¥é¡¼¤¬È¯À¸¤¹¤ë¤È¡¢
154 ¿ô³Ø´Ø¿ô¤ÏÉáÄ̤ϠNaN ¤òÊÖ¤·
155 (Ʊ¤¸¾õ¶·¤Ç°ã¤¦ÃͤòÊÖ¤¹´Ø¿ô¤â¤¢¤ë)¡¢
156 .I errno
157 ¤Ë
158 .B EDOM
159 ¤òÀßÄꤷ¡¢¡Ö̵¸ú (invalid)¡×
160 ÉâÆ°¾®¿ôÅÀÎã³°
161 .RB ( FE_INVALID )
162 ¤ò¾å¤²¤ë¡£
163 .\"O .SS Pole Error
164 .SS ¶Ë¥¨¥é¡¼ (pole error)
165 .\"O A
166 .\"O .I 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
171 .\"O .BR HUGE_VAL ,
172 .\"O .BR HUGE_VALF ,
173 .\"O or
174 .\"O .BR HUGE_VALL ,
175 .\"O depending on whether the function result type is
176 .\"O .IR double ,
177 .\"O .IR float ,
178 .\"O or
179 .\"O .IR "long double" .
180 .\"O The sign of the result is that which is mathematically correct for
181 .\"O the function.
182 .I ¶Ë¥¨¥é¡¼
183 ¤¬È¯À¸¤¹¤ë¤Î¤Ï¡¢´Ø¿ô¤Î¿ô³ØŪ¤Ê·ë²Ì¤¬Ìµ¸ÂÂ礽¤Î¤â¤Î¤È¤Ê¤ë¾ì¹ç¤Ç¤¢¤ë
184 (Î㤨¤Ð
185 0 ¤ÎÂпô¤ÏÉé¤Î̵¸ÂÂç¤Ç¤¢¤ë)¡£
186 ¶Ë¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤È¡¢¤½¤Î´Ø¿ô¤ÎÊÖ¤êÃͤϠ(Éä¹æÉÕ¤­¤Î)
187 .BR HUGE_VAL ,
188 .BR HUGE_VALF ,
189 .B HUGE_VALL
190 ¤Î¤¤¤º¤ì¤«¤È¤Ê¤ë (Á°µ­¤ÎÃͤΤ¦¤Á¤É¤ì¤¬Ê֤뤫¤Ï´Ø¿ô¤ÎÊÖ¤êÃͤη¿¤Ë¤è¤ê·è¤Þ¤ê¡¢
191 ¤½¤ì¤¾¤ì
192 .IR double ,
193 .IR float ,
194 .I "long double"
195 ¤ËÂбþ¤¹¤ë)¡£
196 ·ë²Ì¤ÎÉä¹æ¤Ï¡¢¤½¤Î´Ø¿ô¤Î¿ô³ØŪ¤ÊÄêµÁ¤«¤é·èÄꤵ¤ì¤ë¡£
197 .\"O .I errno
198 .\"O is set to
199 .\"O .BR ERANGE ,
200 .\"O and a "divide-by-zero"
201 .\"O .RB ( FE_DIVBYZERO )
202 .\"O floating-point exception is raised.
203 .I errno
204 ¤Ï
205 .B ERANGE
206 ¤ËÀßÄꤵ¤ì¡¢¡Ö0 ¤Ë¤è¤ë½ü»» (divide-by-zero)¡×
207 ÉâÆ°¾®¿ôÅÀÎã³°
208 .RB ( FE_DIVBYZERO )
209 ¤¬¾å¤¬¤ë¡£
210 .\"O .SS Range Error
211 .SS ÈÏ°Ï¥¨¥é¡¼ (range ¥¨¥é¡¼)
212 .\"O A
213 .\"O .I range error
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.
218 .I ÈÏ°Ï¥¨¥é¡¼
219 ¤¬È¯À¸¤¹¤ë¤Î¤Ï¡¢´Ø¿ô¤Î·ë²Ì¤ÎÃͤ¬¤½¤Î´Ø¿ô¤ÎÊÖ¤êÃͤη¿¤Ç¤Ïɽ¸½¤Ç¤­¤Ê¤¤¾ì¹ç
220 ¤Ç¤¢¤ë¡£´Ø¿ô¤ÎÊÖ¤êÃͤϡ¢ÈÏ°Ï¥¨¥é¡¼¤¬¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Ç¤¢¤Ã¤¿¤«¥¢¥ó¥À¡¼¥Õ¥í¡¼
221 ¤Ç¤¢¤Ã¤¿¤«¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
222
223 .\"O A floating result
224 .\"O .I overflows
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
229 .\"O .BR HUGE_VAL ,
230 .\"O .BR HUGE_VALF ,
231 .\"O or
232 .\"O .BR HUGE_VALL ,
233 .\"O depending on whether the function result type is
234 .\"O .IR double ,
235 .\"O .IR float ,
236 .\"O or
237 .\"O .IR "long double" .
238 .\"O .I errno
239 .\"O is set to
240 .\"O .BR ERANGE ,
241 .\"O and an "overflow"
242 .\"O .RB ( FE_OVERFLOW )
243 .\"O floating-point exception is raised.
244 ÉâÆ°¾®¿ôÅÀ¤Î¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Ï¡¢·ë²Ì¤¬Í­¸Â¤À¤¬¡¢Â礭²á¤®¤Æ
245 ·ë²Ì¤òÊÖ¤¹·¿¤Ç¤Ïɽ¸½¤Ç¤­¤Ê¤¤¾ì¹ç¤ËȯÀ¸¤¹¤ë¡£
246 ¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬È¯À¸¤¹¤ë¤È¡¢
247 ¤½¤Î´Ø¿ô¤Ï
248 .BR HUGE_VAL ,
249 .BR HUGE_VALF ,
250 .B HUGE_VALL
251 ¤Î¤¤¤º¤ì¤«¤òÊÖ¤¹ (Á°µ­¤ÎÃͤΤ¦¤Á¤É¤ì¤¬Ê֤뤫¤Ï´Ø¿ô¤ÎÊÖ¤êÃͤη¿¤Ë¤è¤ê·è¤Þ¤ê¡¢
252 ¤½¤ì¤¾¤ì
253 .IR double ,
254 .IR float ,
255 .I "long double"
256 ¤ËÂбþ¤¹¤ë)¡£
257 .I errno
258 ¤Ï
259 .B ERANGE
260 ¤ËÀßÄꤵ¤ì¡¢¡Ö¥ª¡¼¥Ð¡¼¥Õ¥í¡¼ (overflow)¡×
261 ÉâÆ°¾®¿ôÅÀÎã³°
262 .RB ( FE_OVERFLOW )
263 ¤¬¾å¤¬¤ë¡£
264
265 .\"O A floating result
266 .\"O .I underflows
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) ¤ÎÃͤòÊÖ¤¹¡¢¤È¤Ê¤Ã¤Æ¤¤¤ë)¡£
278 .\"O .I errno
279 .\"O may be set to
280 .\"O .BR ERANGE ,
281 .\"O and an "overflow"
282 .\"O .RB ( FE_UNDERFLOW )
283 .\"O floating-point exception may be raised.
284 .I errno
285 ¤Ï
286 .B ERANGE
287 ¤ËÀßÄꤵ¤ì¡¢¡Ö¥¢¥ó¥À¡¼¥Õ¥í¡¼¡×ÉâÆ°¾®¿ôÅÀÎã³°
288 .RB ( FE_UNDERFLOW )
289 ¤¬¾å¤¬¤ë¡£
290
291 .\"O Some functions deliver a range error if the supplied argument value,
292 .\"O or the correct function result, would be
293 .\"O .IR subnormal .
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 ¤¬
306 ´Þ¤Þ¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
307 .\"O .SH NOTES
308 .SH Ãí°Õ
309 .\"O The
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 ¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë
313 .I math_errhandling
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
318 .\"O .RI ( errno ,
319 .\"O exceptions retrievable via
320 .\"O .BR fettestexcept (3))
321 .\"O is in use.
322 ¤³¤Î¼±Ê̻Ҥϡ¢2 ¤Ä¤Î¥¨¥é¡¼ÄÌÃε¡¹½
323 .RI ( errno
324 ¤È
325 .BR fetestexcept (3)
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.
332 .\"O Some also set
333 .\"O .IR errno .
334 .\"O A few functions set
335 .\"O .IR errno ,
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 ¤Û¤È¤ó¤É¤Î´Ø¿ô (¤¿¤À¤·Á´Éô¤Ç¤Ï¤Ê¤¤) ¤Ï¥¨¥é¡¼»þ¤ËÎã³°¤ò¾å¤²¤ë¡£
343 ¤¤¤¯¤Ä¤«¤Î´Ø¿ô¤Ï
344 .I errno
345 ¤âÀßÄꤹ¤ë¡£
346 .I errno
347 ¤òÀßÄꤹ¤ë¤¬¡¢Îã³°¤ò¾å¤²¤Ê¤¤´Ø¿ô¤â¾¯¤·¤À¤±Â¸ºß¤¹¤ë¡£
348 ¤É¤Á¤é¤â¹Ô¤ï¤Ê¤¤´Ø¿ô¤â¤´¤¯¾¯¿ô¤À¤¬Â¸ºß¤¹¤ë¡£
349 ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¸Ä¡¹¤Î¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤ò»²¾È¤Î¤³¤È¡£
350
351 .\"O To avoid the complexities of using
352 .\"O .I errno
353 .\"O and
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.
358 .I errno
359 ¤È
360 .BR fetestexcept (3)
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
366 .\"O .BR log (3)'s
367 .\"O argument is not a NaN and is not zero (a pole error) or
368 .\"O less than zero (a domain error):
369 Î㤨¤Ð¡¢°Ê²¼¤Î¥³¡¼¥É¤Ï¡¢
370 .BR log (3)
371 ¤Î°ú¤­¿ô¤¬ NaN ¤Ç¤â (¶Ë¥¨¥é¡¼¤È¤Ê¤ë) 0 ¤Ç¤â (Îΰ襨¥é¡¼¤È¤Ê¤ë) 0 Ì¤Ëþ
372 ¤Ç¤â¤Ê¤¤¤³¤È¤òÊݾڤ¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
373 .in +4n
374 .nf
375
376 double x, r;
377
378 if (isnan(x) || islessequal(x, 0)) {
379     /* Deal with NaN / pole error / domain error */
380 }
381
382 r = log(x);
383
384 .fi
385 .in
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 ¤³¤Î¥Ú¡¼¥¸¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¤³¤È¤Ï¡¢
392 .RI ( <complex.h>
393 ¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë) Ê£ÁÇ¿ô´Ø¿ô¤Ë¤Ï¤¢¤Æ¤Ï¤Þ¤é¤Ê¤¤¡£
394 °ìÈ̤ˡ¢C99 ¤ä POSIX.1-2001 ¤Ç¤Ï¤³¤ì¤é¤Î´Ø¿ô¤¬¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤ò
395 Í׵ᤷ¤Æ¤Ê¤¤¡£
396
397 .\"O The
398 .\"O .BR gcc (1)
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
403 .\"O .I errno
404 .\"O on error.
405 .\"O (The
406 .\"O .BR gcc (1)
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).
412 .BR gcc (1)
413 ¤Î
414 .I "-fno-math-errno"
415 ¥ª¥×¥·¥ç¥ó¤ò»È¤¦¤È¡¢¼Â¹Ô¥Õ¥¡¥¤¥ë¤Ç¡¢É¸½à¤Î¼ÂÁõ¤è¤ê¤â¹â®¤Ê¿ô³Ø´Ø¿ô¤Î
416 ¼ÂÁõ¤¬»ÈÍѤµ¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¤¬¡¢
417 ¥¨¥é¡¼»þ¤Ë
418 .I errno
419 ¤¬ÀßÄꤵ¤ì¤Ê¤¤
420 .RB ( gcc (1)
421 ¤Î
422 .I "-ffast-math"
423 ¥ª¥×¥·¥ç¥ó¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤â
424 .I "-fno-math-errno"
425 ¤ÏÍ­¸ú¤Ë¤Ê¤ë)¡£
426 ¤³¤Î¥ª¥×¥·¥ç¥ó¤ò»ØÄꤷ¤¿¾ì¹ç¤Ç¤â¡¢
427 .BR fetestexcept (3)
428 ¤ò»È¤Ã¤¿¥¨¥é¡¼¤Î¸¡ºº¤Ï²Äǽ¤Ç¤¢¤ë¡£
429 .\"O .SH SEE ALSO
430 .SH ´ØÏ¢¹àÌÜ
431 .BR gcc (1),
432 .BR errno (3),
433 .BR fenv (3),
434 .BR fpclassify (3),
435 .BR INFINITY (3),
436 .BR isgreater (3),
437 .BR matherr (3),
438 .BR nan (3)
439 .br
440 .I "info libc"