Update.
[glibc.git] / sysdeps / libm-ieee754 / k_standard.c
blobada1df1a990bda516ee2b93f8027d7689371f5ab
1 /* @(#)k_standard.c 5.1 93/09/24 */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: k_standard.c,v 1.6 1995/05/10 20:46:35 jtc Exp $";
15 #endif
17 #include "math.h"
18 #include "math_private.h"
19 #include <errno.h>
21 #include <assert.h>
23 #ifndef _USE_WRITE
24 #include <stdio.h> /* fputs(), stderr */
25 #define WRITE2(u,v) fputs(u, stderr)
26 #else /* !defined(_USE_WRITE) */
27 #include <unistd.h> /* write */
28 #define WRITE2(u,v) write(2, u, v)
29 #undef fflush
30 #endif /* !defined(_USE_WRITE) */
32 #ifdef __STDC__
33 static const double zero = 0.0; /* used as const */
34 #else
35 static double zero = 0.0; /* used as const */
36 #endif
39 * Standard conformance (non-IEEE) on exception cases.
40 * Mapping:
41 * 1 -- acos(|x|>1)
42 * 2 -- asin(|x|>1)
43 * 3 -- atan2(+-0,+-0)
44 * 4 -- hypot overflow
45 * 5 -- cosh overflow
46 * 6 -- exp overflow
47 * 7 -- exp underflow
48 * 8 -- y0(0)
49 * 9 -- y0(-ve)
50 * 10-- y1(0)
51 * 11-- y1(-ve)
52 * 12-- yn(0)
53 * 13-- yn(-ve)
54 * 14-- lgamma(finite) overflow
55 * 15-- lgamma(-integer)
56 * 16-- log(0)
57 * 17-- log(x<0)
58 * 18-- log10(0)
59 * 19-- log10(x<0)
60 * 20-- pow(0.0,0.0)
61 * 21-- pow(x,y) overflow
62 * 22-- pow(x,y) underflow
63 * 23-- pow(0,negative)
64 * 24-- pow(neg,non-integral)
65 * 25-- sinh(finite) overflow
66 * 26-- sqrt(negative)
67 * 27-- fmod(x,0)
68 * 28-- remainder(x,0)
69 * 29-- acosh(x<1)
70 * 30-- atanh(|x|>1)
71 * 31-- atanh(|x|=1)
72 * 32-- scalb overflow
73 * 33-- scalb underflow
74 * 34-- j0(|x|>X_TLOSS)
75 * 35-- y0(x>X_TLOSS)
76 * 36-- j1(|x|>X_TLOSS)
77 * 37-- y1(x>X_TLOSS)
78 * 38-- jn(|x|>X_TLOSS, n)
79 * 39-- yn(x>X_TLOSS, n)
80 * 40-- gamma(finite) overflow
81 * 41-- gamma(-integer)
82 * 42-- pow(NaN,0.0)
86 #ifdef __STDC__
87 double __kernel_standard(double x, double y, int type)
88 #else
89 double __kernel_standard(x,y,type)
90 double x,y; int type;
91 #endif
93 struct exception exc;
94 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
95 #define HUGE_VAL inf
96 double inf = 0.0;
98 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
99 #endif
101 #ifdef _USE_WRITE
102 (void) fflush(stdout);
103 #endif
104 exc.arg1 = x;
105 exc.arg2 = y;
106 switch(type) {
107 case 1:
108 case 101:
109 case 201:
110 /* acos(|x|>1) */
111 exc.type = DOMAIN;
112 exc.name = type < 100 ? "acos" : (type < 200
113 ? "acosf" : "acosl");;
114 if (_LIB_VERSION == _SVID_)
115 exc.retval = HUGE;
116 else
117 exc.retval = NAN;
118 if (_LIB_VERSION == _POSIX_)
119 __set_errno (EDOM);
120 else if (!__matherr(&exc)) {
121 if(_LIB_VERSION == _SVID_) {
122 (void) WRITE2("acos: DOMAIN error\n", 19);
124 __set_errno (EDOM);
126 break;
127 case 2:
128 case 102:
129 case 202:
130 /* asin(|x|>1) */
131 exc.type = DOMAIN;
132 exc.name = type < 100 ? "asin" : (type < 200
133 ? "asinf" : "asinl");
134 if (_LIB_VERSION == _SVID_)
135 exc.retval = HUGE;
136 else
137 exc.retval = NAN;
138 if(_LIB_VERSION == _POSIX_)
139 __set_errno (EDOM);
140 else if (!__matherr(&exc)) {
141 if(_LIB_VERSION == _SVID_) {
142 (void) WRITE2("asin: DOMAIN error\n", 19);
144 __set_errno (EDOM);
146 break;
147 case 3:
148 case 103:
149 case 203:
150 /* atan2(+-0,+-0) */
151 exc.arg1 = y;
152 exc.arg2 = x;
153 exc.type = DOMAIN;
154 exc.name = type < 100 ? "atan2" : (type < 200
155 ? "atan2f" : "atan2l");
156 assert (_LIB_VERSION == _SVID_);
157 exc.retval = HUGE;
158 if(_LIB_VERSION == _POSIX_)
159 __set_errno (EDOM);
160 else if (!__matherr(&exc)) {
161 if(_LIB_VERSION == _SVID_) {
162 (void) WRITE2("atan2: DOMAIN error\n", 20);
164 __set_errno (EDOM);
166 break;
167 case 4:
168 case 104:
169 case 204:
170 /* hypot(finite,finite) overflow */
171 exc.type = OVERFLOW;
172 exc.name = type < 100 ? "hypot" : (type < 200
173 ? "hypotf" : "hypotl");
174 if (_LIB_VERSION == _SVID_)
175 exc.retval = HUGE;
176 else
177 exc.retval = HUGE_VAL;
178 if (_LIB_VERSION == _POSIX_)
179 __set_errno (ERANGE);
180 else if (!__matherr(&exc)) {
181 __set_errno (ERANGE);
183 break;
184 case 5:
185 case 105:
186 case 205:
187 /* cosh(finite) overflow */
188 exc.type = OVERFLOW;
189 exc.name = type < 100 ? "cosh" : (type < 200
190 ? "coshf" : "coshl");
191 if (_LIB_VERSION == _SVID_)
192 exc.retval = HUGE;
193 else
194 exc.retval = HUGE_VAL;
195 if (_LIB_VERSION == _POSIX_)
196 __set_errno (ERANGE);
197 else if (!__matherr(&exc)) {
198 __set_errno (ERANGE);
200 break;
201 case 6:
202 case 106:
203 case 206:
204 /* exp(finite) overflow */
205 exc.type = OVERFLOW;
206 exc.name = type < 100 ? "exp" : (type < 200
207 ? "expf" : "expl");
208 if (_LIB_VERSION == _SVID_)
209 exc.retval = HUGE;
210 else
211 exc.retval = HUGE_VAL;
212 if (_LIB_VERSION == _POSIX_)
213 __set_errno (ERANGE);
214 else if (!__matherr(&exc)) {
215 __set_errno (ERANGE);
217 break;
218 case 7:
219 case 107:
220 case 207:
221 /* exp(finite) underflow */
222 exc.type = UNDERFLOW;
223 exc.name = type < 100 ? "exp" : (type < 200
224 ? "expf" : "expl");
225 exc.retval = zero;
226 if (_LIB_VERSION == _POSIX_)
227 __set_errno (ERANGE);
228 else if (!__matherr(&exc)) {
229 __set_errno (ERANGE);
231 break;
232 case 8:
233 case 108:
234 case 208:
235 /* y0(0) = -inf */
236 exc.type = DOMAIN; /* should be SING for IEEE */
237 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
238 if (_LIB_VERSION == _SVID_)
239 exc.retval = -HUGE;
240 else
241 exc.retval = -HUGE_VAL;
242 if (_LIB_VERSION == _POSIX_)
243 __set_errno (EDOM);
244 else if (!__matherr(&exc)) {
245 if (_LIB_VERSION == _SVID_) {
246 (void) WRITE2("y0: DOMAIN error\n", 17);
248 __set_errno (EDOM);
250 break;
251 case 9:
252 case 109:
253 case 209:
254 /* y0(x<0) = NaN */
255 exc.type = DOMAIN;
256 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
257 if (_LIB_VERSION == _SVID_)
258 exc.retval = -HUGE;
259 else
260 exc.retval = -HUGE_VAL;
261 if (_LIB_VERSION == _POSIX_)
262 __set_errno (EDOM);
263 else if (!__matherr(&exc)) {
264 if (_LIB_VERSION == _SVID_) {
265 (void) WRITE2("y0: DOMAIN error\n", 17);
267 __set_errno (EDOM);
269 break;
270 case 10:
271 case 110:
272 case 210:
273 /* y1(0) = -inf */
274 exc.type = DOMAIN; /* should be SING for IEEE */
275 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
276 if (_LIB_VERSION == _SVID_)
277 exc.retval = -HUGE;
278 else
279 exc.retval = -HUGE_VAL;
280 if (_LIB_VERSION == _POSIX_)
281 __set_errno (EDOM);
282 else if (!__matherr(&exc)) {
283 if (_LIB_VERSION == _SVID_) {
284 (void) WRITE2("y1: DOMAIN error\n", 17);
286 __set_errno (EDOM);
288 break;
289 case 11:
290 case 111:
291 case 211:
292 /* y1(x<0) = NaN */
293 exc.type = DOMAIN;
294 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
295 if (_LIB_VERSION == _SVID_)
296 exc.retval = -HUGE;
297 else
298 exc.retval = -HUGE_VAL;
299 if (_LIB_VERSION == _POSIX_)
300 __set_errno (EDOM);
301 else if (!__matherr(&exc)) {
302 if (_LIB_VERSION == _SVID_) {
303 (void) WRITE2("y1: DOMAIN error\n", 17);
305 __set_errno (EDOM);
307 break;
308 case 12:
309 case 112:
310 case 212:
311 /* yn(n,0) = -inf */
312 exc.type = DOMAIN; /* should be SING for IEEE */
313 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
314 if (_LIB_VERSION == _SVID_)
315 exc.retval = -HUGE;
316 else
317 exc.retval = -HUGE_VAL;
318 if (_LIB_VERSION == _POSIX_)
319 __set_errno (EDOM);
320 else if (!__matherr(&exc)) {
321 if (_LIB_VERSION == _SVID_) {
322 (void) WRITE2("yn: DOMAIN error\n", 17);
324 __set_errno (EDOM);
326 break;
327 case 13:
328 case 113:
329 case 213:
330 /* yn(x<0) = NaN */
331 exc.type = DOMAIN;
332 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
333 if (_LIB_VERSION == _SVID_)
334 exc.retval = -HUGE;
335 else
336 exc.retval = -HUGE_VAL;
337 if (_LIB_VERSION == _POSIX_)
338 __set_errno (EDOM);
339 else if (!__matherr(&exc)) {
340 if (_LIB_VERSION == _SVID_) {
341 (void) WRITE2("yn: DOMAIN error\n", 17);
343 __set_errno (EDOM);
345 break;
346 case 14:
347 case 114:
348 case 214:
349 /* lgamma(finite) overflow */
350 exc.type = OVERFLOW;
351 exc.name = type < 100 ? "lgamma" : (type < 200
352 ? "lgammaf" : "lgammal");
353 if (_LIB_VERSION == _SVID_)
354 exc.retval = HUGE;
355 else
356 exc.retval = HUGE_VAL;
357 if (_LIB_VERSION == _POSIX_)
358 __set_errno (ERANGE);
359 else if (!__matherr(&exc)) {
360 __set_errno (ERANGE);
362 break;
363 case 15:
364 case 115:
365 case 215:
366 /* lgamma(-integer) or lgamma(0) */
367 exc.type = SING;
368 exc.name = type < 100 ? "lgamma" : (type < 200
369 ? "lgammaf" : "lgammal");
370 if (_LIB_VERSION == _SVID_)
371 exc.retval = HUGE;
372 else
373 exc.retval = HUGE_VAL;
374 if (_LIB_VERSION == _POSIX_)
375 __set_errno (EDOM);
376 else if (!__matherr(&exc)) {
377 if (_LIB_VERSION == _SVID_) {
378 (void) WRITE2("lgamma: SING error\n", 19);
380 __set_errno (EDOM);
382 break;
383 case 16:
384 case 116:
385 case 216:
386 /* log(0) */
387 exc.type = SING;
388 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
389 if (_LIB_VERSION == _SVID_)
390 exc.retval = -HUGE;
391 else
392 exc.retval = -HUGE_VAL;
393 if (_LIB_VERSION == _POSIX_)
394 __set_errno (ERANGE);
395 else if (!__matherr(&exc)) {
396 if (_LIB_VERSION == _SVID_) {
397 (void) WRITE2("log: SING error\n", 16);
399 __set_errno (EDOM);
401 break;
402 case 17:
403 case 117:
404 case 217:
405 /* log(x<0) */
406 exc.type = DOMAIN;
407 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
408 if (_LIB_VERSION == _SVID_)
409 exc.retval = -HUGE;
410 else
411 exc.retval = NAN;
412 if (_LIB_VERSION == _POSIX_)
413 __set_errno (EDOM);
414 else if (!__matherr(&exc)) {
415 if (_LIB_VERSION == _SVID_) {
416 (void) WRITE2("log: DOMAIN error\n", 18);
418 __set_errno (EDOM);
420 break;
421 case 18:
422 case 118:
423 case 218:
424 /* log10(0) */
425 exc.type = SING;
426 exc.name = type < 100 ? "log10" : (type < 200
427 ? "log10f" : "log10l");
428 if (_LIB_VERSION == _SVID_)
429 exc.retval = -HUGE;
430 else
431 exc.retval = -HUGE_VAL;
432 if (_LIB_VERSION == _POSIX_)
433 __set_errno (ERANGE);
434 else if (!__matherr(&exc)) {
435 if (_LIB_VERSION == _SVID_) {
436 (void) WRITE2("log10: SING error\n", 18);
438 __set_errno (EDOM);
440 break;
441 case 19:
442 case 119:
443 case 219:
444 /* log10(x<0) */
445 exc.type = DOMAIN;
446 exc.name = type < 100 ? "log10" : (type < 200
447 ? "log10f" : "log10l");
448 if (_LIB_VERSION == _SVID_)
449 exc.retval = -HUGE;
450 else
451 exc.retval = NAN;
452 if (_LIB_VERSION == _POSIX_)
453 __set_errno (EDOM);
454 else if (!__matherr(&exc)) {
455 if (_LIB_VERSION == _SVID_) {
456 (void) WRITE2("log10: DOMAIN error\n", 20);
458 __set_errno (EDOM);
460 break;
461 case 20:
462 case 120:
463 case 220:
464 /* pow(0.0,0.0) */
465 /* error only if _LIB_VERSION == _SVID_ */
466 exc.type = DOMAIN;
467 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
468 exc.retval = zero;
469 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
470 else if (!__matherr(&exc)) {
471 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
472 __set_errno (EDOM);
474 break;
475 case 21:
476 case 121:
477 case 221:
478 /* pow(x,y) overflow */
479 exc.type = OVERFLOW;
480 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
481 if (_LIB_VERSION == _SVID_) {
482 exc.retval = HUGE;
483 y *= 0.5;
484 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
485 } else {
486 exc.retval = HUGE_VAL;
487 y *= 0.5;
488 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
490 if (_LIB_VERSION == _POSIX_)
491 __set_errno (ERANGE);
492 else if (!__matherr(&exc)) {
493 __set_errno (ERANGE);
495 break;
496 case 22:
497 case 122:
498 case 222:
499 /* pow(x,y) underflow */
500 exc.type = UNDERFLOW;
501 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
502 exc.retval = zero;
503 if (_LIB_VERSION == _POSIX_)
504 __set_errno (ERANGE);
505 else if (!__matherr(&exc)) {
506 __set_errno (ERANGE);
508 break;
509 case 23:
510 case 123:
511 case 223:
512 /* -0**neg */
513 exc.type = DOMAIN;
514 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
515 if (_LIB_VERSION == _SVID_)
516 exc.retval = zero;
517 else
518 exc.retval = -HUGE_VAL;
519 if (_LIB_VERSION == _POSIX_)
520 __set_errno (EDOM);
521 else if (!__matherr(&exc)) {
522 if (_LIB_VERSION == _SVID_) {
523 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
525 __set_errno (EDOM);
527 break;
528 case 43:
529 case 143:
530 case 243:
531 /* +0**neg */
532 exc.type = DOMAIN;
533 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
534 if (_LIB_VERSION == _SVID_)
535 exc.retval = zero;
536 else
537 exc.retval = HUGE_VAL;
538 if (_LIB_VERSION == _POSIX_)
539 __set_errno (EDOM);
540 else if (!__matherr(&exc)) {
541 if (_LIB_VERSION == _SVID_) {
542 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
544 __set_errno (EDOM);
546 break;
547 case 24:
548 case 124:
549 case 224:
550 /* neg**non-integral */
551 exc.type = DOMAIN;
552 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
553 if (_LIB_VERSION == _SVID_)
554 exc.retval = zero;
555 else
556 exc.retval = zero/zero; /* X/Open allow NaN */
557 if (_LIB_VERSION == _POSIX_)
558 __set_errno (EDOM);
559 else if (!__matherr(&exc)) {
560 if (_LIB_VERSION == _SVID_) {
561 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
563 __set_errno (EDOM);
565 break;
566 case 25:
567 case 125:
568 case 225:
569 /* sinh(finite) overflow */
570 exc.type = OVERFLOW;
571 exc.name = type < 100 ? "sinh" : (type < 200
572 ? "sinhf" : "sinhl");
573 if (_LIB_VERSION == _SVID_)
574 exc.retval = ( (x>zero) ? HUGE : -HUGE);
575 else
576 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
577 if (_LIB_VERSION == _POSIX_)
578 __set_errno (ERANGE);
579 else if (!__matherr(&exc)) {
580 __set_errno (ERANGE);
582 break;
583 case 26:
584 case 126:
585 case 226:
586 /* sqrt(x<0) */
587 exc.type = DOMAIN;
588 exc.name = type < 100 ? "sqrt" : (type < 200
589 ? "sqrtf" : "sqrtl");
590 if (_LIB_VERSION == _SVID_)
591 exc.retval = zero;
592 else
593 exc.retval = zero/zero;
594 if (_LIB_VERSION == _POSIX_)
595 __set_errno (EDOM);
596 else if (!__matherr(&exc)) {
597 if (_LIB_VERSION == _SVID_) {
598 (void) WRITE2("sqrt: DOMAIN error\n", 19);
600 __set_errno (EDOM);
602 break;
603 case 27:
604 case 127:
605 case 227:
606 /* fmod(x,0) */
607 exc.type = DOMAIN;
608 exc.name = type < 100 ? "fmod" : (type < 200
609 ? "fmodf" : "fmodl");
610 if (_LIB_VERSION == _SVID_)
611 exc.retval = x;
612 else
613 exc.retval = zero/zero;
614 if (_LIB_VERSION == _POSIX_)
615 __set_errno (EDOM);
616 else if (!__matherr(&exc)) {
617 if (_LIB_VERSION == _SVID_) {
618 (void) WRITE2("fmod: DOMAIN error\n", 20);
620 __set_errno (EDOM);
622 break;
623 case 28:
624 case 128:
625 case 228:
626 /* remainder(x,0) */
627 exc.type = DOMAIN;
628 exc.name = type < 100 ? "remainder" : (type < 200
629 ? "remainderf"
630 : "remainderl");
631 exc.retval = zero/zero;
632 if (_LIB_VERSION == _POSIX_)
633 __set_errno (EDOM);
634 else if (!__matherr(&exc)) {
635 if (_LIB_VERSION == _SVID_) {
636 (void) WRITE2("remainder: DOMAIN error\n", 24);
638 __set_errno (EDOM);
640 break;
641 case 29:
642 case 129:
643 case 229:
644 /* acosh(x<1) */
645 exc.type = DOMAIN;
646 exc.name = type < 100 ? "acosh" : (type < 200
647 ? "acoshf" : "acoshl");
648 exc.retval = zero/zero;
649 if (_LIB_VERSION == _POSIX_)
650 __set_errno (EDOM);
651 else if (!__matherr(&exc)) {
652 if (_LIB_VERSION == _SVID_) {
653 (void) WRITE2("acosh: DOMAIN error\n", 20);
655 __set_errno (EDOM);
657 break;
658 case 30:
659 case 130:
660 case 230:
661 /* atanh(|x|>1) */
662 exc.type = DOMAIN;
663 exc.name = type < 100 ? "atanh" : (type < 200
664 ? "atanhf" : "atanhl");
665 exc.retval = zero/zero;
666 if (_LIB_VERSION == _POSIX_)
667 __set_errno (EDOM);
668 else if (!__matherr(&exc)) {
669 if (_LIB_VERSION == _SVID_) {
670 (void) WRITE2("atanh: DOMAIN error\n", 20);
672 __set_errno (EDOM);
674 break;
675 case 31:
676 case 131:
677 case 231:
678 /* atanh(|x|=1) */
679 exc.type = SING;
680 exc.name = type < 100 ? "atanh" : (type < 200
681 ? "atanhf" : "atanhl");
682 exc.retval = x/zero; /* sign(x)*inf */
683 if (_LIB_VERSION == _POSIX_)
684 __set_errno (EDOM);
685 else if (!__matherr(&exc)) {
686 if (_LIB_VERSION == _SVID_) {
687 (void) WRITE2("atanh: SING error\n", 18);
689 __set_errno (EDOM);
691 break;
692 case 32:
693 case 132:
694 case 232:
695 /* scalb overflow; SVID also returns +-HUGE_VAL */
696 exc.type = OVERFLOW;
697 exc.name = type < 100 ? "scalb" : (type < 200
698 ? "scalbf" : "scalbl");
699 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
700 if (_LIB_VERSION == _POSIX_)
701 __set_errno (ERANGE);
702 else if (!__matherr(&exc)) {
703 __set_errno (ERANGE);
705 break;
706 case 33:
707 case 133:
708 case 233:
709 /* scalb underflow */
710 exc.type = UNDERFLOW;
711 exc.name = type < 100 ? "scalb" : (type < 200
712 ? "scalbf" : "scalbl");
713 exc.retval = __copysign(zero,x);
714 if (_LIB_VERSION == _POSIX_)
715 __set_errno (ERANGE);
716 else if (!__matherr(&exc)) {
717 __set_errno (ERANGE);
719 break;
720 case 34:
721 case 134:
722 case 234:
723 /* j0(|x|>X_TLOSS) */
724 exc.type = TLOSS;
725 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
726 exc.retval = zero;
727 if (_LIB_VERSION == _POSIX_)
728 __set_errno (ERANGE);
729 else if (!__matherr(&exc)) {
730 if (_LIB_VERSION == _SVID_) {
731 (void) WRITE2(exc.name, 2);
732 (void) WRITE2(": TLOSS error\n", 14);
734 __set_errno (ERANGE);
736 break;
737 case 35:
738 case 135:
739 case 235:
740 /* y0(x>X_TLOSS) */
741 exc.type = TLOSS;
742 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
743 exc.retval = zero;
744 if (_LIB_VERSION == _POSIX_)
745 __set_errno (ERANGE);
746 else if (!__matherr(&exc)) {
747 if (_LIB_VERSION == _SVID_) {
748 (void) WRITE2(exc.name, 2);
749 (void) WRITE2(": TLOSS error\n", 14);
751 __set_errno (ERANGE);
753 break;
754 case 36:
755 case 136:
756 case 236:
757 /* j1(|x|>X_TLOSS) */
758 exc.type = TLOSS;
759 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
760 exc.retval = zero;
761 if (_LIB_VERSION == _POSIX_)
762 __set_errno (ERANGE);
763 else if (!__matherr(&exc)) {
764 if (_LIB_VERSION == _SVID_) {
765 (void) WRITE2(exc.name, 2);
766 (void) WRITE2(": TLOSS error\n", 14);
768 __set_errno (ERANGE);
770 break;
771 case 37:
772 case 137:
773 case 237:
774 /* y1(x>X_TLOSS) */
775 exc.type = TLOSS;
776 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
777 exc.retval = zero;
778 if (_LIB_VERSION == _POSIX_)
779 __set_errno (ERANGE);
780 else if (!__matherr(&exc)) {
781 if (_LIB_VERSION == _SVID_) {
782 (void) WRITE2(exc.name, 2);
783 (void) WRITE2(": TLOSS error\n", 14);
785 __set_errno (ERANGE);
787 break;
788 case 38:
789 case 138:
790 case 238:
791 /* jn(|x|>X_TLOSS) */
792 exc.type = TLOSS;
793 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
794 exc.retval = zero;
795 if (_LIB_VERSION == _POSIX_)
796 __set_errno (ERANGE);
797 else if (!__matherr(&exc)) {
798 if (_LIB_VERSION == _SVID_) {
799 (void) WRITE2(exc.name, 2);
800 (void) WRITE2(": TLOSS error\n", 14);
802 __set_errno (ERANGE);
804 break;
805 case 39:
806 case 139:
807 case 239:
808 /* yn(x>X_TLOSS) */
809 exc.type = TLOSS;
810 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
811 exc.retval = zero;
812 if (_LIB_VERSION == _POSIX_)
813 __set_errno (ERANGE);
814 else if (!__matherr(&exc)) {
815 if (_LIB_VERSION == _SVID_) {
816 (void) WRITE2(exc.name, 2);
817 (void) WRITE2(": TLOSS error\n", 14);
819 __set_errno (ERANGE);
821 break;
822 case 40:
823 case 140:
824 case 240:
825 /* gamma(finite) overflow */
826 exc.type = OVERFLOW;
827 exc.name = type < 100 ? "gamma" : (type < 200
828 ? "gammaf" : "gammal");
829 if (_LIB_VERSION == _SVID_)
830 exc.retval = HUGE;
831 else
832 exc.retval = HUGE_VAL;
833 if (_LIB_VERSION == _POSIX_)
834 __set_errno (ERANGE);
835 else if (!__matherr(&exc)) {
836 __set_errno (ERANGE);
838 break;
839 case 41:
840 case 141:
841 case 241:
842 /* gamma(-integer) or gamma(0) */
843 exc.type = SING;
844 exc.name = type < 100 ? "gamma" : (type < 200
845 ? "gammaf" : "gammal");
846 if (_LIB_VERSION == _SVID_)
847 exc.retval = HUGE;
848 else
849 exc.retval = HUGE_VAL;
850 if (_LIB_VERSION == _POSIX_)
851 __set_errno (EDOM);
852 else if (!__matherr(&exc)) {
853 if (_LIB_VERSION == _SVID_) {
854 (void) WRITE2("gamma: SING error\n", 18);
856 __set_errno (EDOM);
858 break;
859 case 42:
860 case 142:
861 case 242:
862 /* pow(NaN,0.0) */
863 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
864 exc.type = DOMAIN;
865 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
866 exc.retval = x;
867 if (_LIB_VERSION == _IEEE_ ||
868 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
869 else if (!__matherr(&exc)) {
870 __set_errno (EDOM);
872 break;
874 /* #### Last used is 43/143/243 ### */
876 return exc.retval;