Increase timeout for stdlib/tst-strtod-overflow
[glibc.git] / sysdeps / ieee754 / k_standard.c
blobcd3123046b364a1fe400c24ea128cd414c59384d
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 <float.h>
20 #include <errno.h>
22 #include <assert.h>
24 #ifndef _USE_WRITE
25 #include <stdio.h> /* fputs(), stderr */
26 #define WRITE2(u,v) fputs(u, stderr)
27 #else /* !defined(_USE_WRITE) */
28 #include <unistd.h> /* write */
29 #define WRITE2(u,v) write(2, u, v)
30 #undef fflush
31 #endif /* !defined(_USE_WRITE) */
33 /* XXX gcc versions until now don't delay the 0.0/0.0 division until
34 runtime but produce NaN at copile time. This is wrong since the
35 exceptions are not set correctly. */
36 #if 0
37 static const double zero = 0.0; /* used as const */
38 #else
39 static double zero = 0.0; /* used as const */
40 #endif
43 * Standard conformance (non-IEEE) on exception cases.
44 * Mapping:
45 * 1 -- acos(|x|>1)
46 * 2 -- asin(|x|>1)
47 * 3 -- atan2(+-0,+-0)
48 * 4 -- hypot overflow
49 * 5 -- cosh overflow
50 * 6 -- exp overflow
51 * 7 -- exp underflow
52 * 8 -- y0(0)
53 * 9 -- y0(-ve)
54 * 10-- y1(0)
55 * 11-- y1(-ve)
56 * 12-- yn(0)
57 * 13-- yn(-ve)
58 * 14-- lgamma(finite) overflow
59 * 15-- lgamma(-integer)
60 * 16-- log(0)
61 * 17-- log(x<0)
62 * 18-- log10(0)
63 * 19-- log10(x<0)
64 * 20-- pow(0.0,0.0)
65 * 21-- pow(x,y) overflow
66 * 22-- pow(x,y) underflow
67 * 23-- pow(0,negative)
68 * 24-- pow(neg,non-integral)
69 * 25-- sinh(finite) overflow
70 * 26-- sqrt(negative)
71 * 27-- fmod(x,0)
72 * 28-- remainder(x,0)
73 * 29-- acosh(x<1)
74 * 30-- atanh(|x|>1)
75 * 31-- atanh(|x|=1)
76 * 32-- scalb overflow
77 * 33-- scalb underflow
78 * 34-- j0(|x|>X_TLOSS)
79 * 35-- y0(x>X_TLOSS)
80 * 36-- j1(|x|>X_TLOSS)
81 * 37-- y1(x>X_TLOSS)
82 * 38-- jn(|x|>X_TLOSS, n)
83 * 39-- yn(x>X_TLOSS, n)
84 * 40-- tgamma(finite) overflow
85 * 41-- tgamma(-integer)
86 * 42-- pow(NaN,0.0)
87 * 43-- +0**neg
88 * 44-- exp2 overflow
89 * 45-- exp2 underflow
90 * 46-- exp10 overflow
91 * 47-- exp10 underflow
92 * 48-- log2(0)
93 * 49-- log2(x<0)
94 * 50-- tgamma(+-0)
98 double
99 __kernel_standard(double x, double y, int type)
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 (ERANGE);
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 y *= 0.5;
512 if (x < zero && __rint (y) != y)
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;
1000 float
1001 __kernel_standard_f(float x, float y, int type)
1003 return __kernel_standard(x, y, type);
1006 #ifndef __NO_LONG_DOUBLE_MATH
1007 long double
1008 __kernel_standard_l (long double x, long double y, int type)
1010 double dx, dy;
1011 struct exception exc;
1013 if (isfinite (x))
1015 long double ax = fabsl (x);
1016 if (ax > DBL_MAX)
1017 dx = __copysignl (DBL_MAX, x);
1018 else if (ax > 0 && ax < DBL_MIN)
1019 dx = __copysignl (DBL_MIN, x);
1020 else
1021 dx = x;
1023 else
1024 dx = x;
1025 if (isfinite (y))
1027 long double ay = fabsl (y);
1028 if (ay > DBL_MAX)
1029 dy = __copysignl (DBL_MAX, y);
1030 else if (ay > 0 && ay < DBL_MIN)
1031 dy = __copysignl (DBL_MIN, y);
1032 else
1033 dy = y;
1035 else
1036 dy = y;
1038 switch (type)
1040 case 221:
1041 /* powl (x, y) overflow. */
1042 exc.arg1 = dx;
1043 exc.arg2 = dy;
1044 exc.type = OVERFLOW;
1045 exc.name = "powl";
1046 if (_LIB_VERSION == _SVID_)
1048 exc.retval = HUGE;
1049 y *= 0.5;
1050 if (x < zero && __rintl (y) != y)
1051 exc.retval = -HUGE;
1053 else
1055 exc.retval = HUGE_VAL;
1056 y *= 0.5;
1057 if (x < zero && __rintl (y) != y)
1058 exc.retval = -HUGE_VAL;
1060 if (_LIB_VERSION == _POSIX_)
1061 __set_errno (ERANGE);
1062 else if (!matherr (&exc))
1063 __set_errno (ERANGE);
1064 return exc.retval;
1066 case 222:
1067 /* powl (x, y) underflow. */
1068 exc.arg1 = dx;
1069 exc.arg2 = dy;
1070 exc.type = UNDERFLOW;
1071 exc.name = "powl";
1072 exc.retval = zero;
1073 y *= 0.5;
1074 if (x < zero && __rintl (y) != y)
1075 exc.retval = -zero;
1076 if (_LIB_VERSION == _POSIX_)
1077 __set_errno (ERANGE);
1078 else if (!matherr (&exc))
1079 __set_errno (ERANGE);
1080 return exc.retval;
1082 default:
1083 return __kernel_standard (dx, dy, type);
1086 #endif