Rev 1619 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* @(#)k_standard.c 5.1 93/09/24 */ |
2 | /* |
||
3 | * ==================================================== |
||
4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
||
5 | * |
||
6 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
||
7 | * Permission to use, copy, modify, and distribute this |
||
8 | * software is freely granted, provided that this notice |
||
9 | * is preserved. |
||
10 | * ==================================================== |
||
11 | */ |
||
12 | |||
13 | #ifndef lint |
||
14 | static char rcsid[] = "$\Id: k_standard.c,v 1.2 1995/05/30 05:49:13 rgrimes Exp $"; |
||
15 | #endif |
||
16 | |||
17 | #include "math.h" |
||
18 | #include "math_private.h" |
||
1621 | fabio | 19 | #include <arch/errno.h> |
2 | pj | 20 | |
21 | /* Undefine these if you're actually going to use the FreeBSD libc. */ |
||
22 | #define _USE_WRITE |
||
23 | #define _NO_FFLUSH |
||
24 | |||
25 | #ifndef _USE_WRITE |
||
26 | #include <stdio.h> /* fputs(), stderr */ |
||
27 | #define WRITE2(u,v) fputs(u, stderr) |
||
28 | #else /* !defined(_USE_WRITE) */ |
||
1621 | fabio | 29 | #include <arch/unistd.h> /* write */ |
2 | pj | 30 | #define WRITE2(u,v) write(2, u, v) |
31 | #undef fflush |
||
32 | #endif /* !defined(_USE_WRITE) */ |
||
33 | |||
34 | #ifdef __STDC__ |
||
35 | static const double zero = 0.0; /* used as const */ |
||
36 | #else |
||
37 | static double zero = 0.0; /* used as const */ |
||
38 | #endif |
||
39 | |||
40 | /* |
||
41 | * Standard conformance (non-IEEE) on exception cases. |
||
42 | * Mapping: |
||
43 | * 1 -- acos(|x|>1) |
||
44 | * 2 -- asin(|x|>1) |
||
45 | * 3 -- atan2(+-0,+-0) |
||
46 | * 4 -- hypot overflow |
||
47 | * 5 -- cosh overflow |
||
48 | * 6 -- exp overflow |
||
49 | * 7 -- exp underflow |
||
50 | * 8 -- y0(0) |
||
51 | * 9 -- y0(-ve) |
||
52 | * 10-- y1(0) |
||
53 | * 11-- y1(-ve) |
||
54 | * 12-- yn(0) |
||
55 | * 13-- yn(-ve) |
||
56 | * 14-- lgamma(finite) overflow |
||
57 | * 15-- lgamma(-integer) |
||
58 | * 16-- log(0) |
||
59 | * 17-- log(x<0) |
||
60 | * 18-- log10(0) |
||
61 | * 19-- log10(x<0) |
||
62 | * 20-- pow(0.0,0.0) |
||
63 | * 21-- pow(x,y) overflow |
||
64 | * 22-- pow(x,y) underflow |
||
65 | * 23-- pow(0,negative) |
||
66 | * 24-- pow(neg,non-integral) |
||
67 | * 25-- sinh(finite) overflow |
||
68 | * 26-- sqrt(negative) |
||
69 | * 27-- fmod(x,0) |
||
70 | * 28-- remainder(x,0) |
||
71 | * 29-- acosh(x<1) |
||
72 | * 30-- atanh(|x|>1) |
||
73 | * 31-- atanh(|x|=1) |
||
74 | * 32-- scalb overflow |
||
75 | * 33-- scalb underflow |
||
76 | * 34-- j0(|x|>X_TLOSS) |
||
77 | * 35-- y0(x>X_TLOSS) |
||
78 | * 36-- j1(|x|>X_TLOSS) |
||
79 | * 37-- y1(x>X_TLOSS) |
||
80 | * 38-- jn(|x|>X_TLOSS, n) |
||
81 | * 39-- yn(x>X_TLOSS, n) |
||
82 | * 40-- gamma(finite) overflow |
||
83 | * 41-- gamma(-integer) |
||
84 | * 42-- pow(NaN,0.0) |
||
85 | */ |
||
86 | |||
87 | |||
88 | #ifdef __STDC__ |
||
89 | double __kernel_standard(double x, double y, int type) |
||
90 | #else |
||
91 | double __kernel_standard(x,y,type) |
||
92 | double x,y; int type; |
||
93 | #endif |
||
94 | { |
||
95 | struct exception exc; |
||
96 | #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */ |
||
97 | #define HUGE_VAL inf |
||
98 | double inf = 0.0; |
||
99 | |||
100 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
||
101 | #endif |
||
102 | |||
103 | #if defined(_USE_WRITE) && !defined(_NO_FFLUSH) |
||
104 | (void) fflush(stdout); |
||
105 | #endif |
||
106 | exc.arg1 = x; |
||
107 | exc.arg2 = y; |
||
108 | switch(type) { |
||
109 | case 1: |
||
110 | case 101: |
||
111 | /* acos(|x|>1) */ |
||
112 | exc.type = DOMAIN; |
||
113 | exc.name = type < 100 ? "acos" : "acosf"; |
||
114 | exc.retval = zero; |
||
115 | if (_LIB_VERSION == _POSIX_) |
||
116 | errno = EDOM; |
||
117 | else if (!matherr(&exc)) { |
||
118 | if(_LIB_VERSION == _SVID_) { |
||
119 | (void) WRITE2("acos: DOMAIN error\n", 19); |
||
120 | } |
||
121 | errno = EDOM; |
||
122 | } |
||
123 | break; |
||
124 | case 2: |
||
125 | case 102: |
||
126 | /* asin(|x|>1) */ |
||
127 | exc.type = DOMAIN; |
||
128 | exc.name = type < 100 ? "asin" : "asinf"; |
||
129 | exc.retval = zero; |
||
130 | if(_LIB_VERSION == _POSIX_) |
||
131 | errno = EDOM; |
||
132 | else if (!matherr(&exc)) { |
||
133 | if(_LIB_VERSION == _SVID_) { |
||
134 | (void) WRITE2("asin: DOMAIN error\n", 19); |
||
135 | } |
||
136 | errno = EDOM; |
||
137 | } |
||
138 | break; |
||
139 | case 3: |
||
140 | case 103: |
||
141 | /* atan2(+-0,+-0) */ |
||
142 | exc.arg1 = y; |
||
143 | exc.arg2 = x; |
||
144 | exc.type = DOMAIN; |
||
145 | exc.name = type < 100 ? "atan2" : "atan2f"; |
||
146 | exc.retval = zero; |
||
147 | if(_LIB_VERSION == _POSIX_) |
||
148 | errno = EDOM; |
||
149 | else if (!matherr(&exc)) { |
||
150 | if(_LIB_VERSION == _SVID_) { |
||
151 | (void) WRITE2("atan2: DOMAIN error\n", 20); |
||
152 | } |
||
153 | errno = EDOM; |
||
154 | } |
||
155 | break; |
||
156 | case 4: |
||
157 | case 104: |
||
158 | /* hypot(finite,finite) overflow */ |
||
159 | exc.type = OVERFLOW; |
||
160 | exc.name = type < 100 ? "hypot" : "hypotf"; |
||
161 | if (_LIB_VERSION == _SVID_) |
||
162 | exc.retval = HUGE; |
||
163 | else |
||
164 | exc.retval = HUGE_VAL; |
||
165 | if (_LIB_VERSION == _POSIX_) |
||
166 | errno = ERANGE; |
||
167 | else if (!matherr(&exc)) { |
||
168 | errno = ERANGE; |
||
169 | } |
||
170 | break; |
||
171 | case 5: |
||
172 | case 105: |
||
173 | /* cosh(finite) overflow */ |
||
174 | exc.type = OVERFLOW; |
||
175 | exc.name = type < 100 ? "cosh" : "coshf"; |
||
176 | if (_LIB_VERSION == _SVID_) |
||
177 | exc.retval = HUGE; |
||
178 | else |
||
179 | exc.retval = HUGE_VAL; |
||
180 | if (_LIB_VERSION == _POSIX_) |
||
181 | errno = ERANGE; |
||
182 | else if (!matherr(&exc)) { |
||
183 | errno = ERANGE; |
||
184 | } |
||
185 | break; |
||
186 | case 6: |
||
187 | case 106: |
||
188 | /* exp(finite) overflow */ |
||
189 | exc.type = OVERFLOW; |
||
190 | exc.name = type < 100 ? "exp" : "expf"; |
||
191 | if (_LIB_VERSION == _SVID_) |
||
192 | exc.retval = HUGE; |
||
193 | else |
||
194 | exc.retval = HUGE_VAL; |
||
195 | if (_LIB_VERSION == _POSIX_) |
||
196 | errno = ERANGE; |
||
197 | else if (!matherr(&exc)) { |
||
198 | errno = ERANGE; |
||
199 | } |
||
200 | break; |
||
201 | case 7: |
||
202 | case 107: |
||
203 | /* exp(finite) underflow */ |
||
204 | exc.type = UNDERFLOW; |
||
205 | exc.name = type < 100 ? "exp" : "expf"; |
||
206 | exc.retval = zero; |
||
207 | if (_LIB_VERSION == _POSIX_) |
||
208 | errno = ERANGE; |
||
209 | else if (!matherr(&exc)) { |
||
210 | errno = ERANGE; |
||
211 | } |
||
212 | break; |
||
213 | case 8: |
||
214 | case 108: |
||
215 | /* y0(0) = -inf */ |
||
216 | exc.type = DOMAIN; /* should be SING for IEEE */ |
||
217 | exc.name = type < 100 ? "y0" : "y0f"; |
||
218 | if (_LIB_VERSION == _SVID_) |
||
219 | exc.retval = -HUGE; |
||
220 | else |
||
221 | exc.retval = -HUGE_VAL; |
||
222 | if (_LIB_VERSION == _POSIX_) |
||
223 | errno = EDOM; |
||
224 | else if (!matherr(&exc)) { |
||
225 | if (_LIB_VERSION == _SVID_) { |
||
226 | (void) WRITE2("y0: DOMAIN error\n", 17); |
||
227 | } |
||
228 | errno = EDOM; |
||
229 | } |
||
230 | break; |
||
231 | case 9: |
||
232 | case 109: |
||
233 | /* y0(x<0) = NaN */ |
||
234 | exc.type = DOMAIN; |
||
235 | exc.name = type < 100 ? "y0" : "y0f"; |
||
236 | if (_LIB_VERSION == _SVID_) |
||
237 | exc.retval = -HUGE; |
||
238 | else |
||
239 | exc.retval = -HUGE_VAL; |
||
240 | if (_LIB_VERSION == _POSIX_) |
||
241 | errno = EDOM; |
||
242 | else if (!matherr(&exc)) { |
||
243 | if (_LIB_VERSION == _SVID_) { |
||
244 | (void) WRITE2("y0: DOMAIN error\n", 17); |
||
245 | } |
||
246 | errno = EDOM; |
||
247 | } |
||
248 | break; |
||
249 | case 10: |
||
250 | case 110: |
||
251 | /* y1(0) = -inf */ |
||
252 | exc.type = DOMAIN; /* should be SING for IEEE */ |
||
253 | exc.name = type < 100 ? "y1" : "y1f"; |
||
254 | if (_LIB_VERSION == _SVID_) |
||
255 | exc.retval = -HUGE; |
||
256 | else |
||
257 | exc.retval = -HUGE_VAL; |
||
258 | if (_LIB_VERSION == _POSIX_) |
||
259 | errno = EDOM; |
||
260 | else if (!matherr(&exc)) { |
||
261 | if (_LIB_VERSION == _SVID_) { |
||
262 | (void) WRITE2("y1: DOMAIN error\n", 17); |
||
263 | } |
||
264 | errno = EDOM; |
||
265 | } |
||
266 | break; |
||
267 | case 11: |
||
268 | case 111: |
||
269 | /* y1(x<0) = NaN */ |
||
270 | exc.type = DOMAIN; |
||
271 | exc.name = type < 100 ? "y1" : "y1f"; |
||
272 | if (_LIB_VERSION == _SVID_) |
||
273 | exc.retval = -HUGE; |
||
274 | else |
||
275 | exc.retval = -HUGE_VAL; |
||
276 | if (_LIB_VERSION == _POSIX_) |
||
277 | errno = EDOM; |
||
278 | else if (!matherr(&exc)) { |
||
279 | if (_LIB_VERSION == _SVID_) { |
||
280 | (void) WRITE2("y1: DOMAIN error\n", 17); |
||
281 | } |
||
282 | errno = EDOM; |
||
283 | } |
||
284 | break; |
||
285 | case 12: |
||
286 | case 112: |
||
287 | /* yn(n,0) = -inf */ |
||
288 | exc.type = DOMAIN; /* should be SING for IEEE */ |
||
289 | exc.name = type < 100 ? "yn" : "ynf"; |
||
290 | if (_LIB_VERSION == _SVID_) |
||
291 | exc.retval = -HUGE; |
||
292 | else |
||
293 | exc.retval = -HUGE_VAL; |
||
294 | if (_LIB_VERSION == _POSIX_) |
||
295 | errno = EDOM; |
||
296 | else if (!matherr(&exc)) { |
||
297 | if (_LIB_VERSION == _SVID_) { |
||
298 | (void) WRITE2("yn: DOMAIN error\n", 17); |
||
299 | } |
||
300 | errno = EDOM; |
||
301 | } |
||
302 | break; |
||
303 | case 13: |
||
304 | case 113: |
||
305 | /* yn(x<0) = NaN */ |
||
306 | exc.type = DOMAIN; |
||
307 | exc.name = type < 100 ? "yn" : "ynf"; |
||
308 | if (_LIB_VERSION == _SVID_) |
||
309 | exc.retval = -HUGE; |
||
310 | else |
||
311 | exc.retval = -HUGE_VAL; |
||
312 | if (_LIB_VERSION == _POSIX_) |
||
313 | errno = EDOM; |
||
314 | else if (!matherr(&exc)) { |
||
315 | if (_LIB_VERSION == _SVID_) { |
||
316 | (void) WRITE2("yn: DOMAIN error\n", 17); |
||
317 | } |
||
318 | errno = EDOM; |
||
319 | } |
||
320 | break; |
||
321 | case 14: |
||
322 | case 114: |
||
323 | /* lgamma(finite) overflow */ |
||
324 | exc.type = OVERFLOW; |
||
325 | exc.name = type < 100 ? "lgamma" : "lgammaf"; |
||
326 | if (_LIB_VERSION == _SVID_) |
||
327 | exc.retval = HUGE; |
||
328 | else |
||
329 | exc.retval = HUGE_VAL; |
||
330 | if (_LIB_VERSION == _POSIX_) |
||
331 | errno = ERANGE; |
||
332 | else if (!matherr(&exc)) { |
||
333 | errno = ERANGE; |
||
334 | } |
||
335 | break; |
||
336 | case 15: |
||
337 | case 115: |
||
338 | /* lgamma(-integer) or lgamma(0) */ |
||
339 | exc.type = SING; |
||
340 | exc.name = type < 100 ? "lgamma" : "lgammaf"; |
||
341 | if (_LIB_VERSION == _SVID_) |
||
342 | exc.retval = HUGE; |
||
343 | else |
||
344 | exc.retval = HUGE_VAL; |
||
345 | if (_LIB_VERSION == _POSIX_) |
||
346 | errno = EDOM; |
||
347 | else if (!matherr(&exc)) { |
||
348 | if (_LIB_VERSION == _SVID_) { |
||
349 | (void) WRITE2("lgamma: SING error\n", 19); |
||
350 | } |
||
351 | errno = EDOM; |
||
352 | } |
||
353 | break; |
||
354 | case 16: |
||
355 | case 116: |
||
356 | /* log(0) */ |
||
357 | exc.type = SING; |
||
358 | exc.name = type < 100 ? "log" : "logf"; |
||
359 | if (_LIB_VERSION == _SVID_) |
||
360 | exc.retval = -HUGE; |
||
361 | else |
||
362 | exc.retval = -HUGE_VAL; |
||
363 | if (_LIB_VERSION == _POSIX_) |
||
364 | errno = ERANGE; |
||
365 | else if (!matherr(&exc)) { |
||
366 | if (_LIB_VERSION == _SVID_) { |
||
367 | (void) WRITE2("log: SING error\n", 16); |
||
368 | } |
||
369 | errno = EDOM; |
||
370 | } |
||
371 | break; |
||
372 | case 17: |
||
373 | case 117: |
||
374 | /* log(x<0) */ |
||
375 | exc.type = DOMAIN; |
||
376 | exc.name = type < 100 ? "log" : "logf"; |
||
377 | if (_LIB_VERSION == _SVID_) |
||
378 | exc.retval = -HUGE; |
||
379 | else |
||
380 | exc.retval = -HUGE_VAL; |
||
381 | if (_LIB_VERSION == _POSIX_) |
||
382 | errno = EDOM; |
||
383 | else if (!matherr(&exc)) { |
||
384 | if (_LIB_VERSION == _SVID_) { |
||
385 | (void) WRITE2("log: DOMAIN error\n", 18); |
||
386 | } |
||
387 | errno = EDOM; |
||
388 | } |
||
389 | break; |
||
390 | case 18: |
||
391 | case 118: |
||
392 | /* log10(0) */ |
||
393 | exc.type = SING; |
||
394 | exc.name = type < 100 ? "log10" : "log10f"; |
||
395 | if (_LIB_VERSION == _SVID_) |
||
396 | exc.retval = -HUGE; |
||
397 | else |
||
398 | exc.retval = -HUGE_VAL; |
||
399 | if (_LIB_VERSION == _POSIX_) |
||
400 | errno = ERANGE; |
||
401 | else if (!matherr(&exc)) { |
||
402 | if (_LIB_VERSION == _SVID_) { |
||
403 | (void) WRITE2("log10: SING error\n", 18); |
||
404 | } |
||
405 | errno = EDOM; |
||
406 | } |
||
407 | break; |
||
408 | case 19: |
||
409 | case 119: |
||
410 | /* log10(x<0) */ |
||
411 | exc.type = DOMAIN; |
||
412 | exc.name = type < 100 ? "log10" : "log10f"; |
||
413 | if (_LIB_VERSION == _SVID_) |
||
414 | exc.retval = -HUGE; |
||
415 | else |
||
416 | exc.retval = -HUGE_VAL; |
||
417 | if (_LIB_VERSION == _POSIX_) |
||
418 | errno = EDOM; |
||
419 | else if (!matherr(&exc)) { |
||
420 | if (_LIB_VERSION == _SVID_) { |
||
421 | (void) WRITE2("log10: DOMAIN error\n", 20); |
||
422 | } |
||
423 | errno = EDOM; |
||
424 | } |
||
425 | break; |
||
426 | case 20: |
||
427 | case 120: |
||
428 | /* pow(0.0,0.0) */ |
||
429 | /* error only if _LIB_VERSION == _SVID_ */ |
||
430 | exc.type = DOMAIN; |
||
431 | exc.name = type < 100 ? "pow" : "powf"; |
||
432 | exc.retval = zero; |
||
433 | if (_LIB_VERSION != _SVID_) exc.retval = 1.0; |
||
434 | else if (!matherr(&exc)) { |
||
435 | (void) WRITE2("pow(0,0): DOMAIN error\n", 23); |
||
436 | errno = EDOM; |
||
437 | } |
||
438 | break; |
||
439 | case 21: |
||
440 | case 121: |
||
441 | /* pow(x,y) overflow */ |
||
442 | exc.type = OVERFLOW; |
||
443 | exc.name = type < 100 ? "pow" : "powf"; |
||
444 | if (_LIB_VERSION == _SVID_) { |
||
445 | exc.retval = HUGE; |
||
446 | y *= 0.5; |
||
447 | if(x<zero&&rint(y)!=y) exc.retval = -HUGE; |
||
448 | } else { |
||
449 | exc.retval = HUGE_VAL; |
||
450 | y *= 0.5; |
||
451 | if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL; |
||
452 | } |
||
453 | if (_LIB_VERSION == _POSIX_) |
||
454 | errno = ERANGE; |
||
455 | else if (!matherr(&exc)) { |
||
456 | errno = ERANGE; |
||
457 | } |
||
458 | break; |
||
459 | case 22: |
||
460 | case 122: |
||
461 | /* pow(x,y) underflow */ |
||
462 | exc.type = UNDERFLOW; |
||
463 | exc.name = type < 100 ? "pow" : "powf"; |
||
464 | exc.retval = zero; |
||
465 | if (_LIB_VERSION == _POSIX_) |
||
466 | errno = ERANGE; |
||
467 | else if (!matherr(&exc)) { |
||
468 | errno = ERANGE; |
||
469 | } |
||
470 | break; |
||
471 | case 23: |
||
472 | case 123: |
||
473 | /* 0**neg */ |
||
474 | exc.type = DOMAIN; |
||
475 | exc.name = type < 100 ? "pow" : "powf"; |
||
476 | if (_LIB_VERSION == _SVID_) |
||
477 | exc.retval = zero; |
||
478 | else |
||
479 | exc.retval = -HUGE_VAL; |
||
480 | if (_LIB_VERSION == _POSIX_) |
||
481 | errno = EDOM; |
||
482 | else if (!matherr(&exc)) { |
||
483 | if (_LIB_VERSION == _SVID_) { |
||
484 | (void) WRITE2("pow(0,neg): DOMAIN error\n", 25); |
||
485 | } |
||
486 | errno = EDOM; |
||
487 | } |
||
488 | break; |
||
489 | case 24: |
||
490 | case 124: |
||
491 | /* neg**non-integral */ |
||
492 | exc.type = DOMAIN; |
||
493 | exc.name = type < 100 ? "pow" : "powf"; |
||
494 | if (_LIB_VERSION == _SVID_) |
||
495 | exc.retval = zero; |
||
496 | else |
||
497 | exc.retval = zero/zero; /* X/Open allow NaN */ |
||
498 | if (_LIB_VERSION == _POSIX_) |
||
499 | errno = EDOM; |
||
500 | else if (!matherr(&exc)) { |
||
501 | if (_LIB_VERSION == _SVID_) { |
||
502 | (void) WRITE2("neg**non-integral: DOMAIN error\n", 32); |
||
503 | } |
||
504 | errno = EDOM; |
||
505 | } |
||
506 | break; |
||
507 | case 25: |
||
508 | case 125: |
||
509 | /* sinh(finite) overflow */ |
||
510 | exc.type = OVERFLOW; |
||
511 | exc.name = type < 100 ? "sinh" : "sinhf"; |
||
512 | if (_LIB_VERSION == _SVID_) |
||
513 | exc.retval = ( (x>zero) ? HUGE : -HUGE); |
||
514 | else |
||
515 | exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL); |
||
516 | if (_LIB_VERSION == _POSIX_) |
||
517 | errno = ERANGE; |
||
518 | else if (!matherr(&exc)) { |
||
519 | errno = ERANGE; |
||
520 | } |
||
521 | break; |
||
522 | case 26: |
||
523 | case 126: |
||
524 | /* sqrt(x<0) */ |
||
525 | exc.type = DOMAIN; |
||
526 | exc.name = type < 100 ? "sqrt" : "sqrtf"; |
||
527 | if (_LIB_VERSION == _SVID_) |
||
528 | exc.retval = zero; |
||
529 | else |
||
530 | exc.retval = zero/zero; |
||
531 | if (_LIB_VERSION == _POSIX_) |
||
532 | errno = EDOM; |
||
533 | else if (!matherr(&exc)) { |
||
534 | if (_LIB_VERSION == _SVID_) { |
||
535 | (void) WRITE2("sqrt: DOMAIN error\n", 19); |
||
536 | } |
||
537 | errno = EDOM; |
||
538 | } |
||
539 | break; |
||
540 | case 27: |
||
541 | case 127: |
||
542 | /* fmod(x,0) */ |
||
543 | exc.type = DOMAIN; |
||
544 | exc.name = type < 100 ? "fmod" : "fmodf"; |
||
545 | if (_LIB_VERSION == _SVID_) |
||
546 | exc.retval = x; |
||
547 | else |
||
548 | exc.retval = zero/zero; |
||
549 | if (_LIB_VERSION == _POSIX_) |
||
550 | errno = EDOM; |
||
551 | else if (!matherr(&exc)) { |
||
552 | if (_LIB_VERSION == _SVID_) { |
||
553 | (void) WRITE2("fmod: DOMAIN error\n", 20); |
||
554 | } |
||
555 | errno = EDOM; |
||
556 | } |
||
557 | break; |
||
558 | case 28: |
||
559 | case 128: |
||
560 | /* remainder(x,0) */ |
||
561 | exc.type = DOMAIN; |
||
562 | exc.name = type < 100 ? "remainder" : "remainderf"; |
||
563 | exc.retval = zero/zero; |
||
564 | if (_LIB_VERSION == _POSIX_) |
||
565 | errno = EDOM; |
||
566 | else if (!matherr(&exc)) { |
||
567 | if (_LIB_VERSION == _SVID_) { |
||
568 | (void) WRITE2("remainder: DOMAIN error\n", 24); |
||
569 | } |
||
570 | errno = EDOM; |
||
571 | } |
||
572 | break; |
||
573 | case 29: |
||
574 | case 129: |
||
575 | /* acosh(x<1) */ |
||
576 | exc.type = DOMAIN; |
||
577 | exc.name = type < 100 ? "acosh" : "acoshf"; |
||
578 | exc.retval = zero/zero; |
||
579 | if (_LIB_VERSION == _POSIX_) |
||
580 | errno = EDOM; |
||
581 | else if (!matherr(&exc)) { |
||
582 | if (_LIB_VERSION == _SVID_) { |
||
583 | (void) WRITE2("acosh: DOMAIN error\n", 20); |
||
584 | } |
||
585 | errno = EDOM; |
||
586 | } |
||
587 | break; |
||
588 | case 30: |
||
589 | case 130: |
||
590 | /* atanh(|x|>1) */ |
||
591 | exc.type = DOMAIN; |
||
592 | exc.name = type < 100 ? "atanh" : "atanhf"; |
||
593 | exc.retval = zero/zero; |
||
594 | if (_LIB_VERSION == _POSIX_) |
||
595 | errno = EDOM; |
||
596 | else if (!matherr(&exc)) { |
||
597 | if (_LIB_VERSION == _SVID_) { |
||
598 | (void) WRITE2("atanh: DOMAIN error\n", 20); |
||
599 | } |
||
600 | errno = EDOM; |
||
601 | } |
||
602 | break; |
||
603 | case 31: |
||
604 | case 131: |
||
605 | /* atanh(|x|=1) */ |
||
606 | exc.type = SING; |
||
607 | exc.name = type < 100 ? "atanh" : "atanhf"; |
||
608 | exc.retval = x/zero; /* sign(x)*inf */ |
||
609 | if (_LIB_VERSION == _POSIX_) |
||
610 | errno = EDOM; |
||
611 | else if (!matherr(&exc)) { |
||
612 | if (_LIB_VERSION == _SVID_) { |
||
613 | (void) WRITE2("atanh: SING error\n", 18); |
||
614 | } |
||
615 | errno = EDOM; |
||
616 | } |
||
617 | break; |
||
618 | case 32: |
||
619 | case 132: |
||
620 | /* scalb overflow; SVID also returns +-HUGE_VAL */ |
||
621 | exc.type = OVERFLOW; |
||
622 | exc.name = type < 100 ? "scalb" : "scalbf"; |
||
623 | exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL; |
||
624 | if (_LIB_VERSION == _POSIX_) |
||
625 | errno = ERANGE; |
||
626 | else if (!matherr(&exc)) { |
||
627 | errno = ERANGE; |
||
628 | } |
||
629 | break; |
||
630 | case 33: |
||
631 | case 133: |
||
632 | /* scalb underflow */ |
||
633 | exc.type = UNDERFLOW; |
||
634 | exc.name = type < 100 ? "scalb" : "scalbf"; |
||
635 | exc.retval = copysign(zero,x); |
||
636 | if (_LIB_VERSION == _POSIX_) |
||
637 | errno = ERANGE; |
||
638 | else if (!matherr(&exc)) { |
||
639 | errno = ERANGE; |
||
640 | } |
||
641 | break; |
||
642 | case 34: |
||
643 | case 134: |
||
644 | /* j0(|x|>X_TLOSS) */ |
||
645 | exc.type = TLOSS; |
||
646 | exc.name = type < 100 ? "j0" : "j0f"; |
||
647 | exc.retval = zero; |
||
648 | if (_LIB_VERSION == _POSIX_) |
||
649 | errno = ERANGE; |
||
650 | else if (!matherr(&exc)) { |
||
651 | if (_LIB_VERSION == _SVID_) { |
||
652 | (void) WRITE2(exc.name, 2); |
||
653 | (void) WRITE2(": TLOSS error\n", 14); |
||
654 | } |
||
655 | errno = ERANGE; |
||
656 | } |
||
657 | break; |
||
658 | case 35: |
||
659 | case 135: |
||
660 | /* y0(x>X_TLOSS) */ |
||
661 | exc.type = TLOSS; |
||
662 | exc.name = type < 100 ? "y0" : "y0f"; |
||
663 | exc.retval = zero; |
||
664 | if (_LIB_VERSION == _POSIX_) |
||
665 | errno = ERANGE; |
||
666 | else if (!matherr(&exc)) { |
||
667 | if (_LIB_VERSION == _SVID_) { |
||
668 | (void) WRITE2(exc.name, 2); |
||
669 | (void) WRITE2(": TLOSS error\n", 14); |
||
670 | } |
||
671 | errno = ERANGE; |
||
672 | } |
||
673 | break; |
||
674 | case 36: |
||
675 | case 136: |
||
676 | /* j1(|x|>X_TLOSS) */ |
||
677 | exc.type = TLOSS; |
||
678 | exc.name = type < 100 ? "j1" : "j1f"; |
||
679 | exc.retval = zero; |
||
680 | if (_LIB_VERSION == _POSIX_) |
||
681 | errno = ERANGE; |
||
682 | else if (!matherr(&exc)) { |
||
683 | if (_LIB_VERSION == _SVID_) { |
||
684 | (void) WRITE2(exc.name, 2); |
||
685 | (void) WRITE2(": TLOSS error\n", 14); |
||
686 | } |
||
687 | errno = ERANGE; |
||
688 | } |
||
689 | break; |
||
690 | case 37: |
||
691 | case 137: |
||
692 | /* y1(x>X_TLOSS) */ |
||
693 | exc.type = TLOSS; |
||
694 | exc.name = type < 100 ? "y1" : "y1f"; |
||
695 | exc.retval = zero; |
||
696 | if (_LIB_VERSION == _POSIX_) |
||
697 | errno = ERANGE; |
||
698 | else if (!matherr(&exc)) { |
||
699 | if (_LIB_VERSION == _SVID_) { |
||
700 | (void) WRITE2(exc.name, 2); |
||
701 | (void) WRITE2(": TLOSS error\n", 14); |
||
702 | } |
||
703 | errno = ERANGE; |
||
704 | } |
||
705 | break; |
||
706 | case 38: |
||
707 | case 138: |
||
708 | /* jn(|x|>X_TLOSS) */ |
||
709 | exc.type = TLOSS; |
||
710 | exc.name = type < 100 ? "jn" : "jnf"; |
||
711 | exc.retval = zero; |
||
712 | if (_LIB_VERSION == _POSIX_) |
||
713 | errno = ERANGE; |
||
714 | else if (!matherr(&exc)) { |
||
715 | if (_LIB_VERSION == _SVID_) { |
||
716 | (void) WRITE2(exc.name, 2); |
||
717 | (void) WRITE2(": TLOSS error\n", 14); |
||
718 | } |
||
719 | errno = ERANGE; |
||
720 | } |
||
721 | break; |
||
722 | case 39: |
||
723 | case 139: |
||
724 | /* yn(x>X_TLOSS) */ |
||
725 | exc.type = TLOSS; |
||
726 | exc.name = type < 100 ? "yn" : "ynf"; |
||
727 | exc.retval = zero; |
||
728 | if (_LIB_VERSION == _POSIX_) |
||
729 | errno = ERANGE; |
||
730 | else if (!matherr(&exc)) { |
||
731 | if (_LIB_VERSION == _SVID_) { |
||
732 | (void) WRITE2(exc.name, 2); |
||
733 | (void) WRITE2(": TLOSS error\n", 14); |
||
734 | } |
||
735 | errno = ERANGE; |
||
736 | } |
||
737 | break; |
||
738 | case 40: |
||
739 | case 140: |
||
740 | /* gamma(finite) overflow */ |
||
741 | exc.type = OVERFLOW; |
||
742 | exc.name = type < 100 ? "gamma" : "gammaf"; |
||
743 | if (_LIB_VERSION == _SVID_) |
||
744 | exc.retval = HUGE; |
||
745 | else |
||
746 | exc.retval = HUGE_VAL; |
||
747 | if (_LIB_VERSION == _POSIX_) |
||
748 | errno = ERANGE; |
||
749 | else if (!matherr(&exc)) { |
||
750 | errno = ERANGE; |
||
751 | } |
||
752 | break; |
||
753 | case 41: |
||
754 | case 141: |
||
755 | /* gamma(-integer) or gamma(0) */ |
||
756 | exc.type = SING; |
||
757 | exc.name = type < 100 ? "gamma" : "gammaf"; |
||
758 | if (_LIB_VERSION == _SVID_) |
||
759 | exc.retval = HUGE; |
||
760 | else |
||
761 | exc.retval = HUGE_VAL; |
||
762 | if (_LIB_VERSION == _POSIX_) |
||
763 | errno = EDOM; |
||
764 | else if (!matherr(&exc)) { |
||
765 | if (_LIB_VERSION == _SVID_) { |
||
766 | (void) WRITE2("gamma: SING error\n", 18); |
||
767 | } |
||
768 | errno = EDOM; |
||
769 | } |
||
770 | break; |
||
771 | case 42: |
||
772 | case 142: |
||
773 | /* pow(NaN,0.0) */ |
||
774 | /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ |
||
775 | exc.type = DOMAIN; |
||
776 | exc.name = type < 100 ? "pow" : "powf"; |
||
777 | exc.retval = x; |
||
778 | if (_LIB_VERSION == _IEEE_ || |
||
779 | _LIB_VERSION == _POSIX_) exc.retval = 1.0; |
||
780 | else if (!matherr(&exc)) { |
||
781 | errno = EDOM; |
||
782 | } |
||
783 | break; |
||
784 | } |
||
785 | return exc.retval; |
||
786 | } |