Fix compile error with sys/wait.h.
[glibc.git] / sysdeps / ieee754 / k_standard.c
blobede5157454aec015ea25431f483f95ddf258228a
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
91 * 48-- log2(0)
92 * 49-- log2(x<0)
93 * 50-- tgamma(+-0)
97 #ifdef __STDC__
98 double __kernel_standard(double x, double y, int type)
99 #else
100 double __kernel_standard(x,y,type)
101 double x,y; int type;
102 #endif
104 struct exception exc;
105 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
106 #define HUGE_VAL inf
107 double inf = 0.0;
109 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
110 #endif
112 #ifdef _USE_WRITE
113 (void) fflush(stdout);
114 #endif
115 exc.arg1 = x;
116 exc.arg2 = y;
117 switch(type) {
118 case 1:
119 case 101:
120 case 201:
121 /* acos(|x|>1) */
122 exc.type = DOMAIN;
123 exc.name = type < 100 ? "acos" : (type < 200
124 ? "acosf" : "acosl");;
125 if (_LIB_VERSION == _SVID_)
126 exc.retval = HUGE;
127 else
128 exc.retval = NAN;
129 if (_LIB_VERSION == _POSIX_)
130 __set_errno (EDOM);
131 else if (!matherr(&exc)) {
132 if(_LIB_VERSION == _SVID_) {
133 (void) WRITE2("acos: DOMAIN error\n", 19);
135 __set_errno (EDOM);
137 break;
138 case 2:
139 case 102:
140 case 202:
141 /* asin(|x|>1) */
142 exc.type = DOMAIN;
143 exc.name = type < 100 ? "asin" : (type < 200
144 ? "asinf" : "asinl");
145 if (_LIB_VERSION == _SVID_)
146 exc.retval = HUGE;
147 else
148 exc.retval = NAN;
149 if(_LIB_VERSION == _POSIX_)
150 __set_errno (EDOM);
151 else if (!matherr(&exc)) {
152 if(_LIB_VERSION == _SVID_) {
153 (void) WRITE2("asin: DOMAIN error\n", 19);
155 __set_errno (EDOM);
157 break;
158 case 3:
159 case 103:
160 case 203:
161 /* atan2(+-0,+-0) */
162 exc.arg1 = y;
163 exc.arg2 = x;
164 exc.type = DOMAIN;
165 exc.name = type < 100 ? "atan2" : (type < 200
166 ? "atan2f" : "atan2l");
167 assert (_LIB_VERSION == _SVID_);
168 exc.retval = HUGE;
169 if(_LIB_VERSION == _POSIX_)
170 __set_errno (EDOM);
171 else if (!matherr(&exc)) {
172 if(_LIB_VERSION == _SVID_) {
173 (void) WRITE2("atan2: DOMAIN error\n", 20);
175 __set_errno (EDOM);
177 break;
178 case 4:
179 case 104:
180 case 204:
181 /* hypot(finite,finite) overflow */
182 exc.type = OVERFLOW;
183 exc.name = type < 100 ? "hypot" : (type < 200
184 ? "hypotf" : "hypotl");
185 if (_LIB_VERSION == _SVID_)
186 exc.retval = HUGE;
187 else
188 exc.retval = HUGE_VAL;
189 if (_LIB_VERSION == _POSIX_)
190 __set_errno (ERANGE);
191 else if (!matherr(&exc)) {
192 __set_errno (ERANGE);
194 break;
195 case 5:
196 case 105:
197 case 205:
198 /* cosh(finite) overflow */
199 exc.type = OVERFLOW;
200 exc.name = type < 100 ? "cosh" : (type < 200
201 ? "coshf" : "coshl");
202 if (_LIB_VERSION == _SVID_)
203 exc.retval = HUGE;
204 else
205 exc.retval = HUGE_VAL;
206 if (_LIB_VERSION == _POSIX_)
207 __set_errno (ERANGE);
208 else if (!matherr(&exc)) {
209 __set_errno (ERANGE);
211 break;
212 case 6:
213 case 106:
214 case 206:
215 /* exp(finite) overflow */
216 exc.type = OVERFLOW;
217 exc.name = type < 100 ? "exp" : (type < 200
218 ? "expf" : "expl");
219 if (_LIB_VERSION == _SVID_)
220 exc.retval = HUGE;
221 else
222 exc.retval = HUGE_VAL;
223 if (_LIB_VERSION == _POSIX_)
224 __set_errno (ERANGE);
225 else if (!matherr(&exc)) {
226 __set_errno (ERANGE);
228 break;
229 case 7:
230 case 107:
231 case 207:
232 /* exp(finite) underflow */
233 exc.type = UNDERFLOW;
234 exc.name = type < 100 ? "exp" : (type < 200
235 ? "expf" : "expl");
236 exc.retval = zero;
237 if (_LIB_VERSION == _POSIX_)
238 __set_errno (ERANGE);
239 else if (!matherr(&exc)) {
240 __set_errno (ERANGE);
242 break;
243 case 8:
244 case 108:
245 case 208:
246 /* y0(0) = -inf */
247 exc.type = DOMAIN; /* should be SING for IEEE */
248 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
249 if (_LIB_VERSION == _SVID_)
250 exc.retval = -HUGE;
251 else
252 exc.retval = -HUGE_VAL;
253 if (_LIB_VERSION == _POSIX_)
254 __set_errno (EDOM);
255 else if (!matherr(&exc)) {
256 if (_LIB_VERSION == _SVID_) {
257 (void) WRITE2("y0: DOMAIN error\n", 17);
259 __set_errno (EDOM);
261 break;
262 case 9:
263 case 109:
264 case 209:
265 /* y0(x<0) = NaN */
266 exc.type = DOMAIN;
267 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
268 if (_LIB_VERSION == _SVID_)
269 exc.retval = -HUGE;
270 else
271 exc.retval = -HUGE_VAL;
272 if (_LIB_VERSION == _POSIX_)
273 __set_errno (EDOM);
274 else if (!matherr(&exc)) {
275 if (_LIB_VERSION == _SVID_) {
276 (void) WRITE2("y0: DOMAIN error\n", 17);
278 __set_errno (EDOM);
280 break;
281 case 10:
282 case 110:
283 case 210:
284 /* y1(0) = -inf */
285 exc.type = DOMAIN; /* should be SING for IEEE */
286 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
287 if (_LIB_VERSION == _SVID_)
288 exc.retval = -HUGE;
289 else
290 exc.retval = -HUGE_VAL;
291 if (_LIB_VERSION == _POSIX_)
292 __set_errno (EDOM);
293 else if (!matherr(&exc)) {
294 if (_LIB_VERSION == _SVID_) {
295 (void) WRITE2("y1: DOMAIN error\n", 17);
297 __set_errno (EDOM);
299 break;
300 case 11:
301 case 111:
302 case 211:
303 /* y1(x<0) = NaN */
304 exc.type = DOMAIN;
305 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
306 if (_LIB_VERSION == _SVID_)
307 exc.retval = -HUGE;
308 else
309 exc.retval = -HUGE_VAL;
310 if (_LIB_VERSION == _POSIX_)
311 __set_errno (EDOM);
312 else if (!matherr(&exc)) {
313 if (_LIB_VERSION == _SVID_) {
314 (void) WRITE2("y1: DOMAIN error\n", 17);
316 __set_errno (EDOM);
318 break;
319 case 12:
320 case 112:
321 case 212:
322 /* yn(n,0) = -inf */
323 exc.type = DOMAIN; /* should be SING for IEEE */
324 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
325 if (_LIB_VERSION == _SVID_)
326 exc.retval = -HUGE;
327 else
328 exc.retval = -HUGE_VAL;
329 if (_LIB_VERSION == _POSIX_)
330 __set_errno (EDOM);
331 else if (!matherr(&exc)) {
332 if (_LIB_VERSION == _SVID_) {
333 (void) WRITE2("yn: DOMAIN error\n", 17);
335 __set_errno (EDOM);
337 break;
338 case 13:
339 case 113:
340 case 213:
341 /* yn(x<0) = NaN */
342 exc.type = DOMAIN;
343 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
344 if (_LIB_VERSION == _SVID_)
345 exc.retval = -HUGE;
346 else
347 exc.retval = -HUGE_VAL;
348 if (_LIB_VERSION == _POSIX_)
349 __set_errno (EDOM);
350 else if (!matherr(&exc)) {
351 if (_LIB_VERSION == _SVID_) {
352 (void) WRITE2("yn: DOMAIN error\n", 17);
354 __set_errno (EDOM);
356 break;
357 case 14:
358 case 114:
359 case 214:
360 /* lgamma(finite) overflow */
361 exc.type = OVERFLOW;
362 exc.name = type < 100 ? "lgamma" : (type < 200
363 ? "lgammaf" : "lgammal");
364 if (_LIB_VERSION == _SVID_)
365 exc.retval = HUGE;
366 else
367 exc.retval = HUGE_VAL;
368 if (_LIB_VERSION == _POSIX_)
369 __set_errno (ERANGE);
370 else if (!matherr(&exc)) {
371 __set_errno (ERANGE);
373 break;
374 case 15:
375 case 115:
376 case 215:
377 /* lgamma(-integer) or lgamma(0) */
378 exc.type = SING;
379 exc.name = type < 100 ? "lgamma" : (type < 200
380 ? "lgammaf" : "lgammal");
381 if (_LIB_VERSION == _SVID_)
382 exc.retval = HUGE;
383 else
384 exc.retval = HUGE_VAL;
385 if (_LIB_VERSION == _POSIX_)
386 __set_errno (ERANGE);
387 else if (!matherr(&exc)) {
388 if (_LIB_VERSION == _SVID_) {
389 (void) WRITE2("lgamma: SING error\n", 19);
391 __set_errno (EDOM);
393 break;
394 case 16:
395 case 116:
396 case 216:
397 /* log(0) */
398 exc.type = SING;
399 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
400 if (_LIB_VERSION == _SVID_)
401 exc.retval = -HUGE;
402 else
403 exc.retval = -HUGE_VAL;
404 if (_LIB_VERSION == _POSIX_)
405 __set_errno (ERANGE);
406 else if (!matherr(&exc)) {
407 if (_LIB_VERSION == _SVID_) {
408 (void) WRITE2("log: SING error\n", 16);
410 __set_errno (EDOM);
412 break;
413 case 17:
414 case 117:
415 case 217:
416 /* log(x<0) */
417 exc.type = DOMAIN;
418 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
419 if (_LIB_VERSION == _SVID_)
420 exc.retval = -HUGE;
421 else
422 exc.retval = NAN;
423 if (_LIB_VERSION == _POSIX_)
424 __set_errno (EDOM);
425 else if (!matherr(&exc)) {
426 if (_LIB_VERSION == _SVID_) {
427 (void) WRITE2("log: DOMAIN error\n", 18);
429 __set_errno (EDOM);
431 break;
432 case 18:
433 case 118:
434 case 218:
435 /* log10(0) */
436 exc.type = SING;
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 __set_errno (ERANGE);
445 else if (!matherr(&exc)) {
446 if (_LIB_VERSION == _SVID_) {
447 (void) WRITE2("log10: SING error\n", 18);
449 __set_errno (EDOM);
451 break;
452 case 19:
453 case 119:
454 case 219:
455 /* log10(x<0) */
456 exc.type = DOMAIN;
457 exc.name = type < 100 ? "log10" : (type < 200
458 ? "log10f" : "log10l");
459 if (_LIB_VERSION == _SVID_)
460 exc.retval = -HUGE;
461 else
462 exc.retval = NAN;
463 if (_LIB_VERSION == _POSIX_)
464 __set_errno (EDOM);
465 else if (!matherr(&exc)) {
466 if (_LIB_VERSION == _SVID_) {
467 (void) WRITE2("log10: DOMAIN error\n", 20);
469 __set_errno (EDOM);
471 break;
472 case 20:
473 case 120:
474 case 220:
475 /* pow(0.0,0.0) */
476 /* error only if _LIB_VERSION == _SVID_ */
477 exc.type = DOMAIN;
478 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
479 exc.retval = zero;
480 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
481 else if (!matherr(&exc)) {
482 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
483 __set_errno (EDOM);
485 break;
486 case 21:
487 case 121:
488 case 221:
489 /* pow(x,y) overflow */
490 exc.type = OVERFLOW;
491 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
492 if (_LIB_VERSION == _SVID_) {
493 exc.retval = HUGE;
494 y *= 0.5;
495 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
496 } else {
497 exc.retval = HUGE_VAL;
498 y *= 0.5;
499 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
501 if (_LIB_VERSION == _POSIX_)
502 __set_errno (ERANGE);
503 else if (!matherr(&exc)) {
504 __set_errno (ERANGE);
506 break;
507 case 22:
508 case 122:
509 case 222:
510 /* pow(x,y) underflow */
511 exc.type = UNDERFLOW;
512 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
513 exc.retval = zero;
514 if (_LIB_VERSION == _POSIX_)
515 __set_errno (ERANGE);
516 else if (!matherr(&exc)) {
517 __set_errno (ERANGE);
519 break;
520 case 23:
521 case 123:
522 case 223:
523 /* -0**neg */
524 exc.type = DOMAIN;
525 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
526 if (_LIB_VERSION == _SVID_)
527 exc.retval = zero;
528 else
529 exc.retval = -HUGE_VAL;
530 if (_LIB_VERSION == _POSIX_)
531 __set_errno (ERANGE);
532 else if (!matherr(&exc)) {
533 if (_LIB_VERSION == _SVID_) {
534 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
536 __set_errno (EDOM);
538 break;
539 case 43:
540 case 143:
541 case 243:
542 /* +0**neg */
543 exc.type = DOMAIN;
544 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
545 if (_LIB_VERSION == _SVID_)
546 exc.retval = zero;
547 else
548 exc.retval = HUGE_VAL;
549 if (_LIB_VERSION == _POSIX_)
550 __set_errno (ERANGE);
551 else if (!matherr(&exc)) {
552 if (_LIB_VERSION == _SVID_) {
553 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
555 __set_errno (EDOM);
557 break;
558 case 24:
559 case 124:
560 case 224:
561 /* neg**non-integral */
562 exc.type = DOMAIN;
563 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
564 if (_LIB_VERSION == _SVID_)
565 exc.retval = zero;
566 else
567 exc.retval = zero/zero; /* X/Open allow NaN */
568 if (_LIB_VERSION == _POSIX_)
569 __set_errno (EDOM);
570 else if (!matherr(&exc)) {
571 if (_LIB_VERSION == _SVID_) {
572 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
574 __set_errno (EDOM);
576 break;
577 case 25:
578 case 125:
579 case 225:
580 /* sinh(finite) overflow */
581 exc.type = OVERFLOW;
582 exc.name = type < 100 ? "sinh" : (type < 200
583 ? "sinhf" : "sinhl");
584 if (_LIB_VERSION == _SVID_)
585 exc.retval = ( (x>zero) ? HUGE : -HUGE);
586 else
587 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
588 if (_LIB_VERSION == _POSIX_)
589 __set_errno (ERANGE);
590 else if (!matherr(&exc)) {
591 __set_errno (ERANGE);
593 break;
594 case 26:
595 case 126:
596 case 226:
597 /* sqrt(x<0) */
598 exc.type = DOMAIN;
599 exc.name = type < 100 ? "sqrt" : (type < 200
600 ? "sqrtf" : "sqrtl");
601 if (_LIB_VERSION == _SVID_)
602 exc.retval = zero;
603 else
604 exc.retval = zero/zero;
605 if (_LIB_VERSION == _POSIX_)
606 __set_errno (EDOM);
607 else if (!matherr(&exc)) {
608 if (_LIB_VERSION == _SVID_) {
609 (void) WRITE2("sqrt: DOMAIN error\n", 19);
611 __set_errno (EDOM);
613 break;
614 case 27:
615 case 127:
616 case 227:
617 /* fmod(x,0) */
618 exc.type = DOMAIN;
619 exc.name = type < 100 ? "fmod" : (type < 200
620 ? "fmodf" : "fmodl");
621 if (_LIB_VERSION == _SVID_)
622 exc.retval = x;
623 else
624 exc.retval = zero/zero;
625 if (_LIB_VERSION == _POSIX_)
626 __set_errno (EDOM);
627 else if (!matherr(&exc)) {
628 if (_LIB_VERSION == _SVID_) {
629 (void) WRITE2("fmod: DOMAIN error\n", 20);
631 __set_errno (EDOM);
633 break;
634 case 28:
635 case 128:
636 case 228:
637 /* remainder(x,0) */
638 exc.type = DOMAIN;
639 exc.name = type < 100 ? "remainder" : (type < 200
640 ? "remainderf"
641 : "remainderl");
642 exc.retval = zero/zero;
643 if (_LIB_VERSION == _POSIX_)
644 __set_errno (EDOM);
645 else if (!matherr(&exc)) {
646 if (_LIB_VERSION == _SVID_) {
647 (void) WRITE2("remainder: DOMAIN error\n", 24);
649 __set_errno (EDOM);
651 break;
652 case 29:
653 case 129:
654 case 229:
655 /* acosh(x<1) */
656 exc.type = DOMAIN;
657 exc.name = type < 100 ? "acosh" : (type < 200
658 ? "acoshf" : "acoshl");
659 exc.retval = zero/zero;
660 if (_LIB_VERSION == _POSIX_)
661 __set_errno (EDOM);
662 else if (!matherr(&exc)) {
663 if (_LIB_VERSION == _SVID_) {
664 (void) WRITE2("acosh: DOMAIN error\n", 20);
666 __set_errno (EDOM);
668 break;
669 case 30:
670 case 130:
671 case 230:
672 /* atanh(|x|>1) */
673 exc.type = DOMAIN;
674 exc.name = type < 100 ? "atanh" : (type < 200
675 ? "atanhf" : "atanhl");
676 exc.retval = zero/zero;
677 if (_LIB_VERSION == _POSIX_)
678 __set_errno (EDOM);
679 else if (!matherr(&exc)) {
680 if (_LIB_VERSION == _SVID_) {
681 (void) WRITE2("atanh: DOMAIN error\n", 20);
683 __set_errno (EDOM);
685 break;
686 case 31:
687 case 131:
688 case 231:
689 /* atanh(|x|=1) */
690 exc.type = SING;
691 exc.name = type < 100 ? "atanh" : (type < 200
692 ? "atanhf" : "atanhl");
693 exc.retval = x/zero; /* sign(x)*inf */
694 if (_LIB_VERSION == _POSIX_)
695 __set_errno (ERANGE);
696 else if (!matherr(&exc)) {
697 if (_LIB_VERSION == _SVID_) {
698 (void) WRITE2("atanh: SING error\n", 18);
700 __set_errno (EDOM);
702 break;
703 case 32:
704 case 132:
705 case 232:
706 /* scalb overflow; SVID also returns +-HUGE_VAL */
707 exc.type = OVERFLOW;
708 exc.name = type < 100 ? "scalb" : (type < 200
709 ? "scalbf" : "scalbl");
710 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
711 if (_LIB_VERSION == _POSIX_)
712 __set_errno (ERANGE);
713 else if (!matherr(&exc)) {
714 __set_errno (ERANGE);
716 break;
717 case 33:
718 case 133:
719 case 233:
720 /* scalb underflow */
721 exc.type = UNDERFLOW;
722 exc.name = type < 100 ? "scalb" : (type < 200
723 ? "scalbf" : "scalbl");
724 exc.retval = __copysign(zero,x);
725 if (_LIB_VERSION == _POSIX_)
726 __set_errno (ERANGE);
727 else if (!matherr(&exc)) {
728 __set_errno (ERANGE);
730 break;
731 case 34:
732 case 134:
733 case 234:
734 /* j0(|x|>X_TLOSS) */
735 exc.type = TLOSS;
736 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
737 exc.retval = zero;
738 if (_LIB_VERSION == _POSIX_)
739 __set_errno (ERANGE);
740 else if (!matherr(&exc)) {
741 if (_LIB_VERSION == _SVID_) {
742 (void) WRITE2(exc.name, 2);
743 (void) WRITE2(": TLOSS error\n", 14);
745 __set_errno (ERANGE);
747 break;
748 case 35:
749 case 135:
750 case 235:
751 /* y0(x>X_TLOSS) */
752 exc.type = TLOSS;
753 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
754 exc.retval = zero;
755 if (_LIB_VERSION == _POSIX_)
756 __set_errno (ERANGE);
757 else if (!matherr(&exc)) {
758 if (_LIB_VERSION == _SVID_) {
759 (void) WRITE2(exc.name, 2);
760 (void) WRITE2(": TLOSS error\n", 14);
762 __set_errno (ERANGE);
764 break;
765 case 36:
766 case 136:
767 case 236:
768 /* j1(|x|>X_TLOSS) */
769 exc.type = TLOSS;
770 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
771 exc.retval = zero;
772 if (_LIB_VERSION == _POSIX_)
773 __set_errno (ERANGE);
774 else if (!matherr(&exc)) {
775 if (_LIB_VERSION == _SVID_) {
776 (void) WRITE2(exc.name, 2);
777 (void) WRITE2(": TLOSS error\n", 14);
779 __set_errno (ERANGE);
781 break;
782 case 37:
783 case 137:
784 case 237:
785 /* y1(x>X_TLOSS) */
786 exc.type = TLOSS;
787 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
788 exc.retval = zero;
789 if (_LIB_VERSION == _POSIX_)
790 __set_errno (ERANGE);
791 else if (!matherr(&exc)) {
792 if (_LIB_VERSION == _SVID_) {
793 (void) WRITE2(exc.name, 2);
794 (void) WRITE2(": TLOSS error\n", 14);
796 __set_errno (ERANGE);
798 break;
799 case 38:
800 case 138:
801 case 238:
802 /* jn(|x|>X_TLOSS) */
803 exc.type = TLOSS;
804 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
805 exc.retval = zero;
806 if (_LIB_VERSION == _POSIX_)
807 __set_errno (ERANGE);
808 else if (!matherr(&exc)) {
809 if (_LIB_VERSION == _SVID_) {
810 (void) WRITE2(exc.name, 2);
811 (void) WRITE2(": TLOSS error\n", 14);
813 __set_errno (ERANGE);
815 break;
816 case 39:
817 case 139:
818 case 239:
819 /* yn(x>X_TLOSS) */
820 exc.type = TLOSS;
821 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
822 exc.retval = zero;
823 if (_LIB_VERSION == _POSIX_)
824 __set_errno (ERANGE);
825 else if (!matherr(&exc)) {
826 if (_LIB_VERSION == _SVID_) {
827 (void) WRITE2(exc.name, 2);
828 (void) WRITE2(": TLOSS error\n", 14);
830 __set_errno (ERANGE);
832 break;
833 case 40:
834 case 140:
835 case 240:
836 /* tgamma(finite) overflow */
837 exc.type = OVERFLOW;
838 exc.name = type < 100 ? "tgamma" : (type < 200
839 ? "tgammaf" : "tgammal");
840 exc.retval = HUGE_VAL;
841 if (_LIB_VERSION == _POSIX_)
842 __set_errno (ERANGE);
843 else if (!matherr(&exc)) {
844 __set_errno (ERANGE);
846 break;
847 case 41:
848 case 141:
849 case 241:
850 /* tgamma(-integer) */
851 exc.type = SING;
852 exc.name = type < 100 ? "tgamma" : (type < 200
853 ? "tgammaf" : "tgammal");
854 exc.retval = NAN;
855 if (_LIB_VERSION == _POSIX_)
856 __set_errno (EDOM);
857 else if (!matherr(&exc)) {
858 if (_LIB_VERSION == _SVID_) {
859 (void) WRITE2("tgamma: SING error\n", 18);
860 exc.retval = HUGE_VAL;
862 __set_errno (EDOM);
864 break;
865 case 42:
866 case 142:
867 case 242:
868 /* pow(NaN,0.0) */
869 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
870 exc.type = DOMAIN;
871 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
872 exc.retval = x;
873 if (_LIB_VERSION == _IEEE_ ||
874 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
875 else if (!matherr(&exc)) {
876 __set_errno (EDOM);
878 break;
880 case 44:
881 case 144:
882 case 244:
883 /* exp(finite) overflow */
884 exc.type = OVERFLOW;
885 exc.name = type < 100 ? "exp2" : (type < 200
886 ? "exp2f" : "exp2l");
887 if (_LIB_VERSION == _SVID_)
888 exc.retval = HUGE;
889 else
890 exc.retval = HUGE_VAL;
891 if (_LIB_VERSION == _POSIX_)
892 __set_errno (ERANGE);
893 else if (!matherr(&exc)) {
894 __set_errno (ERANGE);
896 break;
897 case 45:
898 case 145:
899 case 245:
900 /* exp(finite) underflow */
901 exc.type = UNDERFLOW;
902 exc.name = type < 100 ? "exp2" : (type < 200
903 ? "exp2f" : "exp2l");
904 exc.retval = zero;
905 if (_LIB_VERSION == _POSIX_)
906 __set_errno (ERANGE);
907 else if (!matherr(&exc)) {
908 __set_errno (ERANGE);
910 break;
912 case 46:
913 case 146:
914 case 246:
915 /* exp(finite) overflow */
916 exc.type = OVERFLOW;
917 exc.name = type < 100 ? "exp10" : (type < 200
918 ? "exp10f" : "exp10l");
919 if (_LIB_VERSION == _SVID_)
920 exc.retval = HUGE;
921 else
922 exc.retval = HUGE_VAL;
923 if (_LIB_VERSION == _POSIX_)
924 __set_errno (ERANGE);
925 else if (!matherr(&exc)) {
926 __set_errno (ERANGE);
928 break;
929 case 47:
930 case 147:
931 case 247:
932 /* exp(finite) underflow */
933 exc.type = UNDERFLOW;
934 exc.name = type < 100 ? "exp10" : (type < 200
935 ? "exp10f" : "exp10l");
936 exc.retval = zero;
937 if (_LIB_VERSION == _POSIX_)
938 __set_errno (ERANGE);
939 else if (!matherr(&exc)) {
940 __set_errno (ERANGE);
942 break;
943 case 48:
944 case 148:
945 case 248:
946 /* log2(0) */
947 exc.type = SING;
948 exc.name = type < 100 ? "log2" : (type < 200
949 ? "log2f" : "log2l");
950 if (_LIB_VERSION == _SVID_)
951 exc.retval = -HUGE;
952 else
953 exc.retval = -HUGE_VAL;
954 if (_LIB_VERSION == _POSIX_)
955 __set_errno (ERANGE);
956 else if (!matherr(&exc)) {
957 __set_errno (EDOM);
959 break;
960 case 49:
961 case 149:
962 case 249:
963 /* log2(x<0) */
964 exc.type = DOMAIN;
965 exc.name = type < 100 ? "log2" : (type < 200
966 ? "log2f" : "log2l");
967 if (_LIB_VERSION == _SVID_)
968 exc.retval = -HUGE;
969 else
970 exc.retval = NAN;
971 if (_LIB_VERSION == _POSIX_)
972 __set_errno (EDOM);
973 else if (!matherr(&exc)) {
974 __set_errno (EDOM);
976 break;
977 case 50:
978 case 150:
979 case 250:
980 /* tgamma(+-0) */
981 exc.type = SING;
982 exc.name = type < 100 ? "tgamma" : (type < 200
983 ? "tgammaf" : "tgammal");
984 exc.retval = __copysign (HUGE_VAL, x);
985 if (_LIB_VERSION == _POSIX_)
986 __set_errno (ERANGE);
987 else if (!matherr(&exc)) {
988 if (_LIB_VERSION == _SVID_)
989 (void) WRITE2("tgamma: SING error\n", 18);
990 __set_errno (ERANGE);
992 break;
994 /* #### Last used is 50/150/250 ### */
996 return exc.retval;