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