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