Update.
[glibc.git] / sysdeps / libm-ieee754 / k_standard.c
blob22300652e9ed7621129eb7f7ac3d01d195ee4c62
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 /* XXX gcc versions until now don't delay the 0.0/0.0 division until
33 runtime but produce NaN at copile time. This is wrong since the
34 exceptions are not set correctly. */
35 #if 0 && defined __STDC__
36 static const double zero = 0.0; /* used as const */
37 #else
38 static double zero = 0.0; /* used as const */
39 #endif
42 * Standard conformance (non-IEEE) on exception cases.
43 * Mapping:
44 * 1 -- acos(|x|>1)
45 * 2 -- asin(|x|>1)
46 * 3 -- atan2(+-0,+-0)
47 * 4 -- hypot overflow
48 * 5 -- cosh overflow
49 * 6 -- exp overflow
50 * 7 -- exp underflow
51 * 8 -- y0(0)
52 * 9 -- y0(-ve)
53 * 10-- y1(0)
54 * 11-- y1(-ve)
55 * 12-- yn(0)
56 * 13-- yn(-ve)
57 * 14-- lgamma(finite) overflow
58 * 15-- lgamma(-integer)
59 * 16-- log(0)
60 * 17-- log(x<0)
61 * 18-- log10(0)
62 * 19-- log10(x<0)
63 * 20-- pow(0.0,0.0)
64 * 21-- pow(x,y) overflow
65 * 22-- pow(x,y) underflow
66 * 23-- pow(0,negative)
67 * 24-- pow(neg,non-integral)
68 * 25-- sinh(finite) overflow
69 * 26-- sqrt(negative)
70 * 27-- fmod(x,0)
71 * 28-- remainder(x,0)
72 * 29-- acosh(x<1)
73 * 30-- atanh(|x|>1)
74 * 31-- atanh(|x|=1)
75 * 32-- scalb overflow
76 * 33-- scalb underflow
77 * 34-- j0(|x|>X_TLOSS)
78 * 35-- y0(x>X_TLOSS)
79 * 36-- j1(|x|>X_TLOSS)
80 * 37-- y1(x>X_TLOSS)
81 * 38-- jn(|x|>X_TLOSS, n)
82 * 39-- yn(x>X_TLOSS, n)
83 * 40-- tgamma(finite) overflow
84 * 41-- tgamma(-integer)
85 * 42-- pow(NaN,0.0)
86 * 43-- +0**neg
87 * 44-- exp2 overflow
88 * 45-- exp2 underflow
89 * 46-- exp10 overflow
90 * 47-- exp10 underflow
94 #ifdef __STDC__
95 double __kernel_standard(double x, double y, int type)
96 #else
97 double __kernel_standard(x,y,type)
98 double x,y; int type;
99 #endif
101 struct exception exc;
102 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
103 #define HUGE_VAL inf
104 double inf = 0.0;
106 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
107 #endif
109 #ifdef _USE_WRITE
110 (void) fflush(stdout);
111 #endif
112 exc.arg1 = x;
113 exc.arg2 = y;
114 switch(type) {
115 case 1:
116 case 101:
117 case 201:
118 /* acos(|x|>1) */
119 exc.type = DOMAIN;
120 exc.name = type < 100 ? "acos" : (type < 200
121 ? "acosf" : "acosl");;
122 if (_LIB_VERSION == _SVID_)
123 exc.retval = HUGE;
124 else
125 exc.retval = NAN;
126 if (_LIB_VERSION == _POSIX_)
127 __set_errno (EDOM);
128 else if (!matherr(&exc)) {
129 if(_LIB_VERSION == _SVID_) {
130 (void) WRITE2("acos: DOMAIN error\n", 19);
132 __set_errno (EDOM);
134 break;
135 case 2:
136 case 102:
137 case 202:
138 /* asin(|x|>1) */
139 exc.type = DOMAIN;
140 exc.name = type < 100 ? "asin" : (type < 200
141 ? "asinf" : "asinl");
142 if (_LIB_VERSION == _SVID_)
143 exc.retval = HUGE;
144 else
145 exc.retval = NAN;
146 if(_LIB_VERSION == _POSIX_)
147 __set_errno (EDOM);
148 else if (!matherr(&exc)) {
149 if(_LIB_VERSION == _SVID_) {
150 (void) WRITE2("asin: DOMAIN error\n", 19);
152 __set_errno (EDOM);
154 break;
155 case 3:
156 case 103:
157 case 203:
158 /* atan2(+-0,+-0) */
159 exc.arg1 = y;
160 exc.arg2 = x;
161 exc.type = DOMAIN;
162 exc.name = type < 100 ? "atan2" : (type < 200
163 ? "atan2f" : "atan2l");
164 assert (_LIB_VERSION == _SVID_);
165 exc.retval = HUGE;
166 if(_LIB_VERSION == _POSIX_)
167 __set_errno (EDOM);
168 else if (!matherr(&exc)) {
169 if(_LIB_VERSION == _SVID_) {
170 (void) WRITE2("atan2: DOMAIN error\n", 20);
172 __set_errno (EDOM);
174 break;
175 case 4:
176 case 104:
177 case 204:
178 /* hypot(finite,finite) overflow */
179 exc.type = OVERFLOW;
180 exc.name = type < 100 ? "hypot" : (type < 200
181 ? "hypotf" : "hypotl");
182 if (_LIB_VERSION == _SVID_)
183 exc.retval = HUGE;
184 else
185 exc.retval = HUGE_VAL;
186 if (_LIB_VERSION == _POSIX_)
187 __set_errno (ERANGE);
188 else if (!matherr(&exc)) {
189 __set_errno (ERANGE);
191 break;
192 case 5:
193 case 105:
194 case 205:
195 /* cosh(finite) overflow */
196 exc.type = OVERFLOW;
197 exc.name = type < 100 ? "cosh" : (type < 200
198 ? "coshf" : "coshl");
199 if (_LIB_VERSION == _SVID_)
200 exc.retval = HUGE;
201 else
202 exc.retval = HUGE_VAL;
203 if (_LIB_VERSION == _POSIX_)
204 __set_errno (ERANGE);
205 else if (!matherr(&exc)) {
206 __set_errno (ERANGE);
208 break;
209 case 6:
210 case 106:
211 case 206:
212 /* exp(finite) overflow */
213 exc.type = OVERFLOW;
214 exc.name = type < 100 ? "exp" : (type < 200
215 ? "expf" : "expl");
216 if (_LIB_VERSION == _SVID_)
217 exc.retval = HUGE;
218 else
219 exc.retval = HUGE_VAL;
220 if (_LIB_VERSION == _POSIX_)
221 __set_errno (ERANGE);
222 else if (!matherr(&exc)) {
223 __set_errno (ERANGE);
225 break;
226 case 7:
227 case 107:
228 case 207:
229 /* exp(finite) underflow */
230 exc.type = UNDERFLOW;
231 exc.name = type < 100 ? "exp" : (type < 200
232 ? "expf" : "expl");
233 exc.retval = zero;
234 if (_LIB_VERSION == _POSIX_)
235 __set_errno (ERANGE);
236 else if (!matherr(&exc)) {
237 __set_errno (ERANGE);
239 break;
240 case 8:
241 case 108:
242 case 208:
243 /* y0(0) = -inf */
244 exc.type = DOMAIN; /* should be SING for IEEE */
245 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
246 if (_LIB_VERSION == _SVID_)
247 exc.retval = -HUGE;
248 else
249 exc.retval = -HUGE_VAL;
250 if (_LIB_VERSION == _POSIX_)
251 __set_errno (EDOM);
252 else if (!matherr(&exc)) {
253 if (_LIB_VERSION == _SVID_) {
254 (void) WRITE2("y0: DOMAIN error\n", 17);
256 __set_errno (EDOM);
258 break;
259 case 9:
260 case 109:
261 case 209:
262 /* y0(x<0) = NaN */
263 exc.type = DOMAIN;
264 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
265 if (_LIB_VERSION == _SVID_)
266 exc.retval = -HUGE;
267 else
268 exc.retval = -HUGE_VAL;
269 if (_LIB_VERSION == _POSIX_)
270 __set_errno (EDOM);
271 else if (!matherr(&exc)) {
272 if (_LIB_VERSION == _SVID_) {
273 (void) WRITE2("y0: DOMAIN error\n", 17);
275 __set_errno (EDOM);
277 break;
278 case 10:
279 case 110:
280 case 210:
281 /* y1(0) = -inf */
282 exc.type = DOMAIN; /* should be SING for IEEE */
283 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
284 if (_LIB_VERSION == _SVID_)
285 exc.retval = -HUGE;
286 else
287 exc.retval = -HUGE_VAL;
288 if (_LIB_VERSION == _POSIX_)
289 __set_errno (EDOM);
290 else if (!matherr(&exc)) {
291 if (_LIB_VERSION == _SVID_) {
292 (void) WRITE2("y1: DOMAIN error\n", 17);
294 __set_errno (EDOM);
296 break;
297 case 11:
298 case 111:
299 case 211:
300 /* y1(x<0) = NaN */
301 exc.type = DOMAIN;
302 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
303 if (_LIB_VERSION == _SVID_)
304 exc.retval = -HUGE;
305 else
306 exc.retval = -HUGE_VAL;
307 if (_LIB_VERSION == _POSIX_)
308 __set_errno (EDOM);
309 else if (!matherr(&exc)) {
310 if (_LIB_VERSION == _SVID_) {
311 (void) WRITE2("y1: DOMAIN error\n", 17);
313 __set_errno (EDOM);
315 break;
316 case 12:
317 case 112:
318 case 212:
319 /* yn(n,0) = -inf */
320 exc.type = DOMAIN; /* should be SING for IEEE */
321 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
322 if (_LIB_VERSION == _SVID_)
323 exc.retval = -HUGE;
324 else
325 exc.retval = -HUGE_VAL;
326 if (_LIB_VERSION == _POSIX_)
327 __set_errno (EDOM);
328 else if (!matherr(&exc)) {
329 if (_LIB_VERSION == _SVID_) {
330 (void) WRITE2("yn: DOMAIN error\n", 17);
332 __set_errno (EDOM);
334 break;
335 case 13:
336 case 113:
337 case 213:
338 /* yn(x<0) = NaN */
339 exc.type = DOMAIN;
340 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
341 if (_LIB_VERSION == _SVID_)
342 exc.retval = -HUGE;
343 else
344 exc.retval = -HUGE_VAL;
345 if (_LIB_VERSION == _POSIX_)
346 __set_errno (EDOM);
347 else if (!matherr(&exc)) {
348 if (_LIB_VERSION == _SVID_) {
349 (void) WRITE2("yn: DOMAIN error\n", 17);
351 __set_errno (EDOM);
353 break;
354 case 14:
355 case 114:
356 case 214:
357 /* lgamma(finite) overflow */
358 exc.type = OVERFLOW;
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 __set_errno (ERANGE);
367 else if (!matherr(&exc)) {
368 __set_errno (ERANGE);
370 break;
371 case 15:
372 case 115:
373 case 215:
374 /* lgamma(-integer) or lgamma(0) */
375 exc.type = SING;
376 exc.name = type < 100 ? "lgamma" : (type < 200
377 ? "lgammaf" : "lgammal");
378 if (_LIB_VERSION == _SVID_)
379 exc.retval = HUGE;
380 else
381 exc.retval = HUGE_VAL;
382 if (_LIB_VERSION == _POSIX_)
383 __set_errno (EDOM);
384 else if (!matherr(&exc)) {
385 if (_LIB_VERSION == _SVID_) {
386 (void) WRITE2("lgamma: SING error\n", 19);
388 __set_errno (EDOM);
390 break;
391 case 16:
392 case 116:
393 case 216:
394 /* log(0) */
395 exc.type = SING;
396 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
397 if (_LIB_VERSION == _SVID_)
398 exc.retval = -HUGE;
399 else
400 exc.retval = -HUGE_VAL;
401 if (_LIB_VERSION == _POSIX_)
402 __set_errno (ERANGE);
403 else if (!matherr(&exc)) {
404 if (_LIB_VERSION == _SVID_) {
405 (void) WRITE2("log: SING error\n", 16);
407 __set_errno (EDOM);
409 break;
410 case 17:
411 case 117:
412 case 217:
413 /* log(x<0) */
414 exc.type = DOMAIN;
415 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
416 if (_LIB_VERSION == _SVID_)
417 exc.retval = -HUGE;
418 else
419 exc.retval = NAN;
420 if (_LIB_VERSION == _POSIX_)
421 __set_errno (EDOM);
422 else if (!matherr(&exc)) {
423 if (_LIB_VERSION == _SVID_) {
424 (void) WRITE2("log: DOMAIN error\n", 18);
426 __set_errno (EDOM);
428 break;
429 case 18:
430 case 118:
431 case 218:
432 /* log10(0) */
433 exc.type = SING;
434 exc.name = type < 100 ? "log10" : (type < 200
435 ? "log10f" : "log10l");
436 if (_LIB_VERSION == _SVID_)
437 exc.retval = -HUGE;
438 else
439 exc.retval = -HUGE_VAL;
440 if (_LIB_VERSION == _POSIX_)
441 __set_errno (ERANGE);
442 else if (!matherr(&exc)) {
443 if (_LIB_VERSION == _SVID_) {
444 (void) WRITE2("log10: SING error\n", 18);
446 __set_errno (EDOM);
448 break;
449 case 19:
450 case 119:
451 case 219:
452 /* log10(x<0) */
453 exc.type = DOMAIN;
454 exc.name = type < 100 ? "log10" : (type < 200
455 ? "log10f" : "log10l");
456 if (_LIB_VERSION == _SVID_)
457 exc.retval = -HUGE;
458 else
459 exc.retval = NAN;
460 if (_LIB_VERSION == _POSIX_)
461 __set_errno (EDOM);
462 else if (!matherr(&exc)) {
463 if (_LIB_VERSION == _SVID_) {
464 (void) WRITE2("log10: DOMAIN error\n", 20);
466 __set_errno (EDOM);
468 break;
469 case 20:
470 case 120:
471 case 220:
472 /* pow(0.0,0.0) */
473 /* error only if _LIB_VERSION == _SVID_ */
474 exc.type = DOMAIN;
475 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
476 exc.retval = zero;
477 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
478 else if (!matherr(&exc)) {
479 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
480 __set_errno (EDOM);
482 break;
483 case 21:
484 case 121:
485 case 221:
486 /* pow(x,y) overflow */
487 exc.type = OVERFLOW;
488 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
489 if (_LIB_VERSION == _SVID_) {
490 exc.retval = HUGE;
491 y *= 0.5;
492 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
493 } else {
494 exc.retval = HUGE_VAL;
495 y *= 0.5;
496 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
498 if (_LIB_VERSION == _POSIX_)
499 __set_errno (ERANGE);
500 else if (!matherr(&exc)) {
501 __set_errno (ERANGE);
503 break;
504 case 22:
505 case 122:
506 case 222:
507 /* pow(x,y) underflow */
508 exc.type = UNDERFLOW;
509 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
510 exc.retval = zero;
511 if (_LIB_VERSION == _POSIX_)
512 __set_errno (ERANGE);
513 else if (!matherr(&exc)) {
514 __set_errno (ERANGE);
516 break;
517 case 23:
518 case 123:
519 case 223:
520 /* -0**neg */
521 exc.type = DOMAIN;
522 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
523 if (_LIB_VERSION == _SVID_)
524 exc.retval = zero;
525 else
526 exc.retval = -HUGE_VAL;
527 if (_LIB_VERSION == _POSIX_)
528 __set_errno (EDOM);
529 else if (!matherr(&exc)) {
530 if (_LIB_VERSION == _SVID_) {
531 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
533 __set_errno (EDOM);
535 break;
536 case 43:
537 case 143:
538 case 243:
539 /* +0**neg */
540 exc.type = DOMAIN;
541 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
542 if (_LIB_VERSION == _SVID_)
543 exc.retval = zero;
544 else
545 exc.retval = HUGE_VAL;
546 if (_LIB_VERSION == _POSIX_)
547 __set_errno (EDOM);
548 else if (!matherr(&exc)) {
549 if (_LIB_VERSION == _SVID_) {
550 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
552 __set_errno (EDOM);
554 break;
555 case 24:
556 case 124:
557 case 224:
558 /* neg**non-integral */
559 exc.type = DOMAIN;
560 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
561 if (_LIB_VERSION == _SVID_)
562 exc.retval = zero;
563 else
564 exc.retval = zero/zero; /* X/Open allow NaN */
565 if (_LIB_VERSION == _POSIX_)
566 __set_errno (EDOM);
567 else if (!matherr(&exc)) {
568 if (_LIB_VERSION == _SVID_) {
569 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
571 __set_errno (EDOM);
573 break;
574 case 25:
575 case 125:
576 case 225:
577 /* sinh(finite) overflow */
578 exc.type = OVERFLOW;
579 exc.name = type < 100 ? "sinh" : (type < 200
580 ? "sinhf" : "sinhl");
581 if (_LIB_VERSION == _SVID_)
582 exc.retval = ( (x>zero) ? HUGE : -HUGE);
583 else
584 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
585 if (_LIB_VERSION == _POSIX_)
586 __set_errno (ERANGE);
587 else if (!matherr(&exc)) {
588 __set_errno (ERANGE);
590 break;
591 case 26:
592 case 126:
593 case 226:
594 /* sqrt(x<0) */
595 exc.type = DOMAIN;
596 exc.name = type < 100 ? "sqrt" : (type < 200
597 ? "sqrtf" : "sqrtl");
598 if (_LIB_VERSION == _SVID_)
599 exc.retval = zero;
600 else
601 exc.retval = zero/zero;
602 if (_LIB_VERSION == _POSIX_)
603 __set_errno (EDOM);
604 else if (!matherr(&exc)) {
605 if (_LIB_VERSION == _SVID_) {
606 (void) WRITE2("sqrt: DOMAIN error\n", 19);
608 __set_errno (EDOM);
610 break;
611 case 27:
612 case 127:
613 case 227:
614 /* fmod(x,0) */
615 exc.type = DOMAIN;
616 exc.name = type < 100 ? "fmod" : (type < 200
617 ? "fmodf" : "fmodl");
618 if (_LIB_VERSION == _SVID_)
619 exc.retval = x;
620 else
621 exc.retval = zero/zero;
622 if (_LIB_VERSION == _POSIX_)
623 __set_errno (EDOM);
624 else if (!matherr(&exc)) {
625 if (_LIB_VERSION == _SVID_) {
626 (void) WRITE2("fmod: DOMAIN error\n", 20);
628 __set_errno (EDOM);
630 break;
631 case 28:
632 case 128:
633 case 228:
634 /* remainder(x,0) */
635 exc.type = DOMAIN;
636 exc.name = type < 100 ? "remainder" : (type < 200
637 ? "remainderf"
638 : "remainderl");
639 exc.retval = zero/zero;
640 if (_LIB_VERSION == _POSIX_)
641 __set_errno (EDOM);
642 else if (!matherr(&exc)) {
643 if (_LIB_VERSION == _SVID_) {
644 (void) WRITE2("remainder: DOMAIN error\n", 24);
646 __set_errno (EDOM);
648 break;
649 case 29:
650 case 129:
651 case 229:
652 /* acosh(x<1) */
653 exc.type = DOMAIN;
654 exc.name = type < 100 ? "acosh" : (type < 200
655 ? "acoshf" : "acoshl");
656 exc.retval = zero/zero;
657 if (_LIB_VERSION == _POSIX_)
658 __set_errno (EDOM);
659 else if (!matherr(&exc)) {
660 if (_LIB_VERSION == _SVID_) {
661 (void) WRITE2("acosh: DOMAIN error\n", 20);
663 __set_errno (EDOM);
665 break;
666 case 30:
667 case 130:
668 case 230:
669 /* atanh(|x|>1) */
670 exc.type = DOMAIN;
671 exc.name = type < 100 ? "atanh" : (type < 200
672 ? "atanhf" : "atanhl");
673 exc.retval = zero/zero;
674 if (_LIB_VERSION == _POSIX_)
675 __set_errno (EDOM);
676 else if (!matherr(&exc)) {
677 if (_LIB_VERSION == _SVID_) {
678 (void) WRITE2("atanh: DOMAIN error\n", 20);
680 __set_errno (EDOM);
682 break;
683 case 31:
684 case 131:
685 case 231:
686 /* atanh(|x|=1) */
687 exc.type = SING;
688 exc.name = type < 100 ? "atanh" : (type < 200
689 ? "atanhf" : "atanhl");
690 exc.retval = x/zero; /* sign(x)*inf */
691 if (_LIB_VERSION == _POSIX_)
692 __set_errno (EDOM);
693 else if (!matherr(&exc)) {
694 if (_LIB_VERSION == _SVID_) {
695 (void) WRITE2("atanh: SING error\n", 18);
697 __set_errno (EDOM);
699 break;
700 case 32:
701 case 132:
702 case 232:
703 /* scalb overflow; SVID also returns +-HUGE_VAL */
704 exc.type = OVERFLOW;
705 exc.name = type < 100 ? "scalb" : (type < 200
706 ? "scalbf" : "scalbl");
707 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
708 if (_LIB_VERSION == _POSIX_)
709 __set_errno (ERANGE);
710 else if (!matherr(&exc)) {
711 __set_errno (ERANGE);
713 break;
714 case 33:
715 case 133:
716 case 233:
717 /* scalb underflow */
718 exc.type = UNDERFLOW;
719 exc.name = type < 100 ? "scalb" : (type < 200
720 ? "scalbf" : "scalbl");
721 exc.retval = __copysign(zero,x);
722 if (_LIB_VERSION == _POSIX_)
723 __set_errno (ERANGE);
724 else if (!matherr(&exc)) {
725 __set_errno (ERANGE);
727 break;
728 case 34:
729 case 134:
730 case 234:
731 /* j0(|x|>X_TLOSS) */
732 exc.type = TLOSS;
733 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
734 exc.retval = zero;
735 if (_LIB_VERSION == _POSIX_)
736 __set_errno (ERANGE);
737 else if (!matherr(&exc)) {
738 if (_LIB_VERSION == _SVID_) {
739 (void) WRITE2(exc.name, 2);
740 (void) WRITE2(": TLOSS error\n", 14);
742 __set_errno (ERANGE);
744 break;
745 case 35:
746 case 135:
747 case 235:
748 /* y0(x>X_TLOSS) */
749 exc.type = TLOSS;
750 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
751 exc.retval = zero;
752 if (_LIB_VERSION == _POSIX_)
753 __set_errno (ERANGE);
754 else if (!matherr(&exc)) {
755 if (_LIB_VERSION == _SVID_) {
756 (void) WRITE2(exc.name, 2);
757 (void) WRITE2(": TLOSS error\n", 14);
759 __set_errno (ERANGE);
761 break;
762 case 36:
763 case 136:
764 case 236:
765 /* j1(|x|>X_TLOSS) */
766 exc.type = TLOSS;
767 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
768 exc.retval = zero;
769 if (_LIB_VERSION == _POSIX_)
770 __set_errno (ERANGE);
771 else if (!matherr(&exc)) {
772 if (_LIB_VERSION == _SVID_) {
773 (void) WRITE2(exc.name, 2);
774 (void) WRITE2(": TLOSS error\n", 14);
776 __set_errno (ERANGE);
778 break;
779 case 37:
780 case 137:
781 case 237:
782 /* y1(x>X_TLOSS) */
783 exc.type = TLOSS;
784 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
785 exc.retval = zero;
786 if (_LIB_VERSION == _POSIX_)
787 __set_errno (ERANGE);
788 else if (!matherr(&exc)) {
789 if (_LIB_VERSION == _SVID_) {
790 (void) WRITE2(exc.name, 2);
791 (void) WRITE2(": TLOSS error\n", 14);
793 __set_errno (ERANGE);
795 break;
796 case 38:
797 case 138:
798 case 238:
799 /* jn(|x|>X_TLOSS) */
800 exc.type = TLOSS;
801 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
802 exc.retval = zero;
803 if (_LIB_VERSION == _POSIX_)
804 __set_errno (ERANGE);
805 else if (!matherr(&exc)) {
806 if (_LIB_VERSION == _SVID_) {
807 (void) WRITE2(exc.name, 2);
808 (void) WRITE2(": TLOSS error\n", 14);
810 __set_errno (ERANGE);
812 break;
813 case 39:
814 case 139:
815 case 239:
816 /* yn(x>X_TLOSS) */
817 exc.type = TLOSS;
818 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
819 exc.retval = zero;
820 if (_LIB_VERSION == _POSIX_)
821 __set_errno (ERANGE);
822 else if (!matherr(&exc)) {
823 if (_LIB_VERSION == _SVID_) {
824 (void) WRITE2(exc.name, 2);
825 (void) WRITE2(": TLOSS error\n", 14);
827 __set_errno (ERANGE);
829 break;
830 case 40:
831 case 140:
832 case 240:
833 /* gamma(finite) overflow */
834 exc.type = OVERFLOW;
835 exc.name = type < 100 ? "tgamma" : (type < 200
836 ? "tgammaf" : "tgammal");
837 exc.retval = HUGE_VAL;
838 if (_LIB_VERSION == _POSIX_)
839 __set_errno (ERANGE);
840 else if (!matherr(&exc)) {
841 __set_errno (ERANGE);
843 break;
844 case 41:
845 case 141:
846 case 241:
847 /* gamma(-integer) or gamma(0) */
848 exc.type = SING;
849 exc.name = type < 100 ? "tgamma" : (type < 200
850 ? "tgammaf" : "tgammal");
851 exc.retval = NAN;
852 if (_LIB_VERSION == _POSIX_)
853 __set_errno (EDOM);
854 else if (!matherr(&exc)) {
855 if (_LIB_VERSION == _SVID_) {
856 (void) WRITE2("tgamma: SING error\n", 18);
857 exc.retval = HUGE_VAL;
859 __set_errno (EDOM);
861 break;
862 case 42:
863 case 142:
864 case 242:
865 /* pow(NaN,0.0) */
866 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
867 exc.type = DOMAIN;
868 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
869 exc.retval = x;
870 if (_LIB_VERSION == _IEEE_ ||
871 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
872 else if (!matherr(&exc)) {
873 __set_errno (EDOM);
875 break;
877 case 44:
878 case 144:
879 case 244:
880 /* exp(finite) overflow */
881 exc.type = OVERFLOW;
882 exc.name = type < 100 ? "exp2" : (type < 200
883 ? "exp2f" : "exp2l");
884 if (_LIB_VERSION == _SVID_)
885 exc.retval = HUGE;
886 else
887 exc.retval = HUGE_VAL;
888 if (_LIB_VERSION == _POSIX_)
889 __set_errno (ERANGE);
890 else if (!matherr(&exc)) {
891 __set_errno (ERANGE);
893 break;
894 case 45:
895 case 145:
896 case 245:
897 /* exp(finite) underflow */
898 exc.type = UNDERFLOW;
899 exc.name = type < 100 ? "exp2" : (type < 200
900 ? "exp2f" : "exp2l");
901 exc.retval = zero;
902 if (_LIB_VERSION == _POSIX_)
903 __set_errno (ERANGE);
904 else if (!matherr(&exc)) {
905 __set_errno (ERANGE);
907 break;
909 case 46:
910 case 146:
911 case 246:
912 /* exp(finite) overflow */
913 exc.type = OVERFLOW;
914 exc.name = type < 100 ? "exp10" : (type < 200
915 ? "exp10f" : "exp10l");
916 if (_LIB_VERSION == _SVID_)
917 exc.retval = HUGE;
918 else
919 exc.retval = HUGE_VAL;
920 if (_LIB_VERSION == _POSIX_)
921 __set_errno (ERANGE);
922 else if (!matherr(&exc)) {
923 __set_errno (ERANGE);
925 break;
926 case 47:
927 case 147:
928 case 247:
929 /* exp(finite) underflow */
930 exc.type = UNDERFLOW;
931 exc.name = type < 100 ? "exp10" : (type < 200
932 ? "exp10f" : "exp10l");
933 exc.retval = zero;
934 if (_LIB_VERSION == _POSIX_)
935 __set_errno (ERANGE);
936 else if (!matherr(&exc)) {
937 __set_errno (ERANGE);
939 break;
940 /* #### Last used is 47/147/247 ### */
942 return exc.retval;