Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / ieee754 / k_standard.c
blob5399c6682d31a61925668e75b755f7820d3c78ee
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 compile 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 (ERANGE);
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 = NAN;
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 (ERANGE);
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 = NAN;
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 = ((x < 0 && ((int) x & 1) != 0)
326 ? HUGE_VAL
327 : -HUGE_VAL);
328 if (_LIB_VERSION == _POSIX_)
329 __set_errno (ERANGE);
330 else if (!matherr(&exc)) {
331 if (_LIB_VERSION == _SVID_) {
332 (void) WRITE2("yn: DOMAIN error\n", 17);
334 __set_errno (EDOM);
336 break;
337 case 13:
338 case 113:
339 case 213:
340 /* yn(x<0) = NaN */
341 exc.type = DOMAIN;
342 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
343 if (_LIB_VERSION == _SVID_)
344 exc.retval = -HUGE;
345 else
346 exc.retval = NAN;
347 if (_LIB_VERSION == _POSIX_)
348 __set_errno (EDOM);
349 else if (!matherr(&exc)) {
350 if (_LIB_VERSION == _SVID_) {
351 (void) WRITE2("yn: DOMAIN error\n", 17);
353 __set_errno (EDOM);
355 break;
356 case 14:
357 case 114:
358 case 214:
359 /* lgamma(finite) overflow */
360 exc.type = OVERFLOW;
361 exc.name = type < 100 ? "lgamma" : (type < 200
362 ? "lgammaf" : "lgammal");
363 if (_LIB_VERSION == _SVID_)
364 exc.retval = HUGE;
365 else
366 exc.retval = HUGE_VAL;
367 if (_LIB_VERSION == _POSIX_)
368 __set_errno (ERANGE);
369 else if (!matherr(&exc)) {
370 __set_errno (ERANGE);
372 break;
373 case 15:
374 case 115:
375 case 215:
376 /* lgamma(-integer) or lgamma(0) */
377 exc.type = SING;
378 exc.name = type < 100 ? "lgamma" : (type < 200
379 ? "lgammaf" : "lgammal");
380 if (_LIB_VERSION == _SVID_)
381 exc.retval = HUGE;
382 else
383 exc.retval = HUGE_VAL;
384 if (_LIB_VERSION == _POSIX_)
385 __set_errno (ERANGE);
386 else if (!matherr(&exc)) {
387 if (_LIB_VERSION == _SVID_) {
388 (void) WRITE2("lgamma: SING error\n", 19);
390 __set_errno (EDOM);
392 break;
393 case 16:
394 case 116:
395 case 216:
396 /* log(0) */
397 exc.type = SING;
398 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
399 if (_LIB_VERSION == _SVID_)
400 exc.retval = -HUGE;
401 else
402 exc.retval = -HUGE_VAL;
403 if (_LIB_VERSION == _POSIX_)
404 __set_errno (ERANGE);
405 else if (!matherr(&exc)) {
406 if (_LIB_VERSION == _SVID_) {
407 (void) WRITE2("log: SING error\n", 16);
409 __set_errno (EDOM);
411 break;
412 case 17:
413 case 117:
414 case 217:
415 /* log(x<0) */
416 exc.type = DOMAIN;
417 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
418 if (_LIB_VERSION == _SVID_)
419 exc.retval = -HUGE;
420 else
421 exc.retval = NAN;
422 if (_LIB_VERSION == _POSIX_)
423 __set_errno (EDOM);
424 else if (!matherr(&exc)) {
425 if (_LIB_VERSION == _SVID_) {
426 (void) WRITE2("log: DOMAIN error\n", 18);
428 __set_errno (EDOM);
430 break;
431 case 18:
432 case 118:
433 case 218:
434 /* log10(0) */
435 exc.type = SING;
436 exc.name = type < 100 ? "log10" : (type < 200
437 ? "log10f" : "log10l");
438 if (_LIB_VERSION == _SVID_)
439 exc.retval = -HUGE;
440 else
441 exc.retval = -HUGE_VAL;
442 if (_LIB_VERSION == _POSIX_)
443 __set_errno (ERANGE);
444 else if (!matherr(&exc)) {
445 if (_LIB_VERSION == _SVID_) {
446 (void) WRITE2("log10: SING error\n", 18);
448 __set_errno (EDOM);
450 break;
451 case 19:
452 case 119:
453 case 219:
454 /* log10(x<0) */
455 exc.type = DOMAIN;
456 exc.name = type < 100 ? "log10" : (type < 200
457 ? "log10f" : "log10l");
458 if (_LIB_VERSION == _SVID_)
459 exc.retval = -HUGE;
460 else
461 exc.retval = NAN;
462 if (_LIB_VERSION == _POSIX_)
463 __set_errno (EDOM);
464 else if (!matherr(&exc)) {
465 if (_LIB_VERSION == _SVID_) {
466 (void) WRITE2("log10: DOMAIN error\n", 20);
468 __set_errno (EDOM);
470 break;
471 case 20:
472 case 120:
473 case 220:
474 /* pow(0.0,0.0) */
475 /* error only if _LIB_VERSION == _SVID_ */
476 exc.type = DOMAIN;
477 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
478 exc.retval = zero;
479 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
480 else if (!matherr(&exc)) {
481 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
482 __set_errno (EDOM);
484 break;
485 case 21:
486 case 121:
487 case 221:
488 /* pow(x,y) overflow */
489 exc.type = OVERFLOW;
490 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
491 if (_LIB_VERSION == _SVID_) {
492 exc.retval = HUGE;
493 y *= 0.5;
494 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
495 } else {
496 exc.retval = HUGE_VAL;
497 y *= 0.5;
498 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
500 if (_LIB_VERSION == _POSIX_)
501 __set_errno (ERANGE);
502 else if (!matherr(&exc)) {
503 __set_errno (ERANGE);
505 break;
506 case 22:
507 case 122:
508 case 222:
509 /* pow(x,y) underflow */
510 exc.type = UNDERFLOW;
511 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
512 exc.retval = zero;
513 y *= 0.5;
514 if (x < zero && __rint (y) != y)
515 exc.retval = -zero;
516 if (_LIB_VERSION == _POSIX_)
517 __set_errno (ERANGE);
518 else if (!matherr(&exc)) {
519 __set_errno (ERANGE);
521 break;
522 case 23:
523 case 123:
524 case 223:
525 /* -0**neg */
526 exc.type = DOMAIN;
527 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
528 if (_LIB_VERSION == _SVID_)
529 exc.retval = zero;
530 else
531 exc.retval = -HUGE_VAL;
532 if (_LIB_VERSION == _POSIX_)
533 __set_errno (ERANGE);
534 else if (!matherr(&exc)) {
535 if (_LIB_VERSION == _SVID_) {
536 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
538 __set_errno (EDOM);
540 break;
541 case 43:
542 case 143:
543 case 243:
544 /* +0**neg */
545 exc.type = DOMAIN;
546 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
547 if (_LIB_VERSION == _SVID_)
548 exc.retval = zero;
549 else
550 exc.retval = HUGE_VAL;
551 if (_LIB_VERSION == _POSIX_)
552 __set_errno (ERANGE);
553 else if (!matherr(&exc)) {
554 if (_LIB_VERSION == _SVID_) {
555 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
557 __set_errno (EDOM);
559 break;
560 case 24:
561 case 124:
562 case 224:
563 /* neg**non-integral */
564 exc.type = DOMAIN;
565 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
566 if (_LIB_VERSION == _SVID_)
567 exc.retval = zero;
568 else
569 exc.retval = zero/zero; /* X/Open allow NaN */
570 if (_LIB_VERSION == _POSIX_)
571 __set_errno (EDOM);
572 else if (!matherr(&exc)) {
573 if (_LIB_VERSION == _SVID_) {
574 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
576 __set_errno (EDOM);
578 break;
579 case 25:
580 case 125:
581 case 225:
582 /* sinh(finite) overflow */
583 exc.type = OVERFLOW;
584 exc.name = type < 100 ? "sinh" : (type < 200
585 ? "sinhf" : "sinhl");
586 if (_LIB_VERSION == _SVID_)
587 exc.retval = ( (x>zero) ? HUGE : -HUGE);
588 else
589 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
590 if (_LIB_VERSION == _POSIX_)
591 __set_errno (ERANGE);
592 else if (!matherr(&exc)) {
593 __set_errno (ERANGE);
595 break;
596 case 26:
597 case 126:
598 case 226:
599 /* sqrt(x<0) */
600 exc.type = DOMAIN;
601 exc.name = type < 100 ? "sqrt" : (type < 200
602 ? "sqrtf" : "sqrtl");
603 if (_LIB_VERSION == _SVID_)
604 exc.retval = zero;
605 else
606 exc.retval = zero/zero;
607 if (_LIB_VERSION == _POSIX_)
608 __set_errno (EDOM);
609 else if (!matherr(&exc)) {
610 if (_LIB_VERSION == _SVID_) {
611 (void) WRITE2("sqrt: DOMAIN error\n", 19);
613 __set_errno (EDOM);
615 break;
616 case 27:
617 case 127:
618 case 227:
619 /* fmod(x,0) */
620 exc.type = DOMAIN;
621 exc.name = type < 100 ? "fmod" : (type < 200
622 ? "fmodf" : "fmodl");
623 if (_LIB_VERSION == _SVID_)
624 exc.retval = x;
625 else
626 exc.retval = zero/zero;
627 if (_LIB_VERSION == _POSIX_)
628 __set_errno (EDOM);
629 else if (!matherr(&exc)) {
630 if (_LIB_VERSION == _SVID_) {
631 (void) WRITE2("fmod: DOMAIN error\n", 20);
633 __set_errno (EDOM);
635 break;
636 case 28:
637 case 128:
638 case 228:
639 /* remainder(x,0) */
640 exc.type = DOMAIN;
641 exc.name = type < 100 ? "remainder" : (type < 200
642 ? "remainderf"
643 : "remainderl");
644 exc.retval = zero/zero;
645 if (_LIB_VERSION == _POSIX_)
646 __set_errno (EDOM);
647 else if (!matherr(&exc)) {
648 if (_LIB_VERSION == _SVID_) {
649 (void) WRITE2("remainder: DOMAIN error\n", 24);
651 __set_errno (EDOM);
653 break;
654 case 29:
655 case 129:
656 case 229:
657 /* acosh(x<1) */
658 exc.type = DOMAIN;
659 exc.name = type < 100 ? "acosh" : (type < 200
660 ? "acoshf" : "acoshl");
661 exc.retval = zero/zero;
662 if (_LIB_VERSION == _POSIX_)
663 __set_errno (EDOM);
664 else if (!matherr(&exc)) {
665 if (_LIB_VERSION == _SVID_) {
666 (void) WRITE2("acosh: DOMAIN error\n", 20);
668 __set_errno (EDOM);
670 break;
671 case 30:
672 case 130:
673 case 230:
674 /* atanh(|x|>1) */
675 exc.type = DOMAIN;
676 exc.name = type < 100 ? "atanh" : (type < 200
677 ? "atanhf" : "atanhl");
678 exc.retval = zero/zero;
679 if (_LIB_VERSION == _POSIX_)
680 __set_errno (EDOM);
681 else if (!matherr(&exc)) {
682 if (_LIB_VERSION == _SVID_) {
683 (void) WRITE2("atanh: DOMAIN error\n", 20);
685 __set_errno (EDOM);
687 break;
688 case 31:
689 case 131:
690 case 231:
691 /* atanh(|x|=1) */
692 exc.type = SING;
693 exc.name = type < 100 ? "atanh" : (type < 200
694 ? "atanhf" : "atanhl");
695 exc.retval = x/zero; /* sign(x)*inf */
696 if (_LIB_VERSION == _POSIX_)
697 __set_errno (ERANGE);
698 else if (!matherr(&exc)) {
699 if (_LIB_VERSION == _SVID_) {
700 (void) WRITE2("atanh: SING error\n", 18);
702 __set_errno (EDOM);
704 break;
705 case 32:
706 case 132:
707 case 232:
708 /* scalb overflow; SVID also returns +-HUGE_VAL */
709 exc.type = OVERFLOW;
710 exc.name = type < 100 ? "scalb" : (type < 200
711 ? "scalbf" : "scalbl");
712 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
713 if (_LIB_VERSION == _POSIX_)
714 __set_errno (ERANGE);
715 else if (!matherr(&exc)) {
716 __set_errno (ERANGE);
718 break;
719 case 33:
720 case 133:
721 case 233:
722 /* scalb underflow */
723 exc.type = UNDERFLOW;
724 exc.name = type < 100 ? "scalb" : (type < 200
725 ? "scalbf" : "scalbl");
726 exc.retval = __copysign(zero,x);
727 if (_LIB_VERSION == _POSIX_)
728 __set_errno (ERANGE);
729 else if (!matherr(&exc)) {
730 __set_errno (ERANGE);
732 break;
733 case 34:
734 case 134:
735 case 234:
736 /* j0(|x|>X_TLOSS) */
737 exc.type = TLOSS;
738 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
739 exc.retval = zero;
740 if (_LIB_VERSION == _POSIX_)
741 __set_errno (ERANGE);
742 else if (!matherr(&exc)) {
743 if (_LIB_VERSION == _SVID_) {
744 (void) WRITE2(exc.name, 2);
745 (void) WRITE2(": TLOSS error\n", 14);
747 __set_errno (ERANGE);
749 break;
750 case 35:
751 case 135:
752 case 235:
753 /* y0(x>X_TLOSS) */
754 exc.type = TLOSS;
755 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
756 exc.retval = zero;
757 if (_LIB_VERSION == _POSIX_)
758 __set_errno (ERANGE);
759 else if (!matherr(&exc)) {
760 if (_LIB_VERSION == _SVID_) {
761 (void) WRITE2(exc.name, 2);
762 (void) WRITE2(": TLOSS error\n", 14);
764 __set_errno (ERANGE);
766 break;
767 case 36:
768 case 136:
769 case 236:
770 /* j1(|x|>X_TLOSS) */
771 exc.type = TLOSS;
772 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
773 exc.retval = zero;
774 if (_LIB_VERSION == _POSIX_)
775 __set_errno (ERANGE);
776 else if (!matherr(&exc)) {
777 if (_LIB_VERSION == _SVID_) {
778 (void) WRITE2(exc.name, 2);
779 (void) WRITE2(": TLOSS error\n", 14);
781 __set_errno (ERANGE);
783 break;
784 case 37:
785 case 137:
786 case 237:
787 /* y1(x>X_TLOSS) */
788 exc.type = TLOSS;
789 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
790 exc.retval = zero;
791 if (_LIB_VERSION == _POSIX_)
792 __set_errno (ERANGE);
793 else if (!matherr(&exc)) {
794 if (_LIB_VERSION == _SVID_) {
795 (void) WRITE2(exc.name, 2);
796 (void) WRITE2(": TLOSS error\n", 14);
798 __set_errno (ERANGE);
800 break;
801 case 38:
802 case 138:
803 case 238:
804 /* jn(|x|>X_TLOSS) */
805 exc.type = TLOSS;
806 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
807 exc.retval = zero;
808 if (_LIB_VERSION == _POSIX_)
809 __set_errno (ERANGE);
810 else if (!matherr(&exc)) {
811 if (_LIB_VERSION == _SVID_) {
812 (void) WRITE2(exc.name, 2);
813 (void) WRITE2(": TLOSS error\n", 14);
815 __set_errno (ERANGE);
817 break;
818 case 39:
819 case 139:
820 case 239:
821 /* yn(x>X_TLOSS) */
822 exc.type = TLOSS;
823 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
824 exc.retval = zero;
825 if (_LIB_VERSION == _POSIX_)
826 __set_errno (ERANGE);
827 else if (!matherr(&exc)) {
828 if (_LIB_VERSION == _SVID_) {
829 (void) WRITE2(exc.name, 2);
830 (void) WRITE2(": TLOSS error\n", 14);
832 __set_errno (ERANGE);
834 break;
835 case 40:
836 case 140:
837 case 240:
838 /* tgamma(finite) overflow */
839 exc.type = OVERFLOW;
840 exc.name = type < 100 ? "tgamma" : (type < 200
841 ? "tgammaf" : "tgammal");
842 exc.retval = __copysign (HUGE_VAL, x);
843 if (_LIB_VERSION == _POSIX_)
844 __set_errno (ERANGE);
845 else if (!matherr(&exc)) {
846 __set_errno (ERANGE);
848 break;
849 case 41:
850 case 141:
851 case 241:
852 /* tgamma(-integer) */
853 exc.type = SING;
854 exc.name = type < 100 ? "tgamma" : (type < 200
855 ? "tgammaf" : "tgammal");
856 exc.retval = NAN;
857 if (_LIB_VERSION == _POSIX_)
858 __set_errno (EDOM);
859 else if (!matherr(&exc)) {
860 if (_LIB_VERSION == _SVID_) {
861 (void) WRITE2("tgamma: SING error\n", 18);
862 exc.retval = HUGE_VAL;
864 __set_errno (EDOM);
866 break;
867 case 42:
868 case 142:
869 case 242:
870 /* pow(NaN,0.0) */
871 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
872 exc.type = DOMAIN;
873 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
874 exc.retval = x;
875 if (_LIB_VERSION == _IEEE_ ||
876 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
877 else if (!matherr(&exc)) {
878 __set_errno (EDOM);
880 break;
882 case 44:
883 case 144:
884 case 244:
885 /* exp(finite) overflow */
886 exc.type = OVERFLOW;
887 exc.name = type < 100 ? "exp2" : (type < 200
888 ? "exp2f" : "exp2l");
889 if (_LIB_VERSION == _SVID_)
890 exc.retval = HUGE;
891 else
892 exc.retval = HUGE_VAL;
893 if (_LIB_VERSION == _POSIX_)
894 __set_errno (ERANGE);
895 else if (!matherr(&exc)) {
896 __set_errno (ERANGE);
898 break;
899 case 45:
900 case 145:
901 case 245:
902 /* exp(finite) underflow */
903 exc.type = UNDERFLOW;
904 exc.name = type < 100 ? "exp2" : (type < 200
905 ? "exp2f" : "exp2l");
906 exc.retval = zero;
907 if (_LIB_VERSION == _POSIX_)
908 __set_errno (ERANGE);
909 else if (!matherr(&exc)) {
910 __set_errno (ERANGE);
912 break;
914 case 46:
915 case 146:
916 case 246:
917 /* exp(finite) overflow */
918 exc.type = OVERFLOW;
919 exc.name = type < 100 ? "exp10" : (type < 200
920 ? "exp10f" : "exp10l");
921 if (_LIB_VERSION == _SVID_)
922 exc.retval = HUGE;
923 else
924 exc.retval = HUGE_VAL;
925 if (_LIB_VERSION == _POSIX_)
926 __set_errno (ERANGE);
927 else if (!matherr(&exc)) {
928 __set_errno (ERANGE);
930 break;
931 case 47:
932 case 147:
933 case 247:
934 /* exp(finite) underflow */
935 exc.type = UNDERFLOW;
936 exc.name = type < 100 ? "exp10" : (type < 200
937 ? "exp10f" : "exp10l");
938 exc.retval = zero;
939 if (_LIB_VERSION == _POSIX_)
940 __set_errno (ERANGE);
941 else if (!matherr(&exc)) {
942 __set_errno (ERANGE);
944 break;
945 case 48:
946 case 148:
947 case 248:
948 /* log2(0) */
949 exc.type = SING;
950 exc.name = type < 100 ? "log2" : (type < 200
951 ? "log2f" : "log2l");
952 if (_LIB_VERSION == _SVID_)
953 exc.retval = -HUGE;
954 else
955 exc.retval = -HUGE_VAL;
956 if (_LIB_VERSION == _POSIX_)
957 __set_errno (ERANGE);
958 else if (!matherr(&exc)) {
959 __set_errno (EDOM);
961 break;
962 case 49:
963 case 149:
964 case 249:
965 /* log2(x<0) */
966 exc.type = DOMAIN;
967 exc.name = type < 100 ? "log2" : (type < 200
968 ? "log2f" : "log2l");
969 if (_LIB_VERSION == _SVID_)
970 exc.retval = -HUGE;
971 else
972 exc.retval = NAN;
973 if (_LIB_VERSION == _POSIX_)
974 __set_errno (EDOM);
975 else if (!matherr(&exc)) {
976 __set_errno (EDOM);
978 break;
979 case 50:
980 case 150:
981 case 250:
982 /* tgamma(+-0) */
983 exc.type = SING;
984 exc.name = type < 100 ? "tgamma" : (type < 200
985 ? "tgammaf" : "tgammal");
986 exc.retval = __copysign (HUGE_VAL, x);
987 if (_LIB_VERSION == _POSIX_)
988 __set_errno (ERANGE);
989 else if (!matherr(&exc)) {
990 if (_LIB_VERSION == _SVID_)
991 (void) WRITE2("tgamma: SING error\n", 18);
992 __set_errno (ERANGE);
994 break;
996 /* #### Last used is 50/150/250 ### */
998 return exc.retval;
1002 float
1003 __kernel_standard_f(float x, float y, int type)
1005 return __kernel_standard(x, y, type);
1008 #ifndef __NO_LONG_DOUBLE_MATH
1009 long double
1010 __kernel_standard_l (long double x, long double y, int type)
1012 double dx, dy;
1013 struct exception exc;
1015 if (isfinite (x))
1017 long double ax = fabsl (x);
1018 if (ax > DBL_MAX)
1019 dx = __copysignl (DBL_MAX, x);
1020 else if (ax > 0 && ax < DBL_MIN)
1021 dx = __copysignl (DBL_MIN, x);
1022 else
1023 dx = x;
1025 else
1026 dx = x;
1027 if (isfinite (y))
1029 long double ay = fabsl (y);
1030 if (ay > DBL_MAX)
1031 dy = __copysignl (DBL_MAX, y);
1032 else if (ay > 0 && ay < DBL_MIN)
1033 dy = __copysignl (DBL_MIN, y);
1034 else
1035 dy = y;
1037 else
1038 dy = y;
1040 switch (type)
1042 case 221:
1043 /* powl (x, y) overflow. */
1044 exc.arg1 = dx;
1045 exc.arg2 = dy;
1046 exc.type = OVERFLOW;
1047 exc.name = "powl";
1048 if (_LIB_VERSION == _SVID_)
1050 exc.retval = HUGE;
1051 y *= 0.5;
1052 if (x < zero && __rintl (y) != y)
1053 exc.retval = -HUGE;
1055 else
1057 exc.retval = HUGE_VAL;
1058 y *= 0.5;
1059 if (x < zero && __rintl (y) != y)
1060 exc.retval = -HUGE_VAL;
1062 if (_LIB_VERSION == _POSIX_)
1063 __set_errno (ERANGE);
1064 else if (!matherr (&exc))
1065 __set_errno (ERANGE);
1066 return exc.retval;
1068 case 222:
1069 /* powl (x, y) underflow. */
1070 exc.arg1 = dx;
1071 exc.arg2 = dy;
1072 exc.type = UNDERFLOW;
1073 exc.name = "powl";
1074 exc.retval = zero;
1075 y *= 0.5;
1076 if (x < zero && __rintl (y) != y)
1077 exc.retval = -zero;
1078 if (_LIB_VERSION == _POSIX_)
1079 __set_errno (ERANGE);
1080 else if (!matherr (&exc))
1081 __set_errno (ERANGE);
1082 return exc.retval;
1084 default:
1085 return __kernel_standard (dx, dy, type);
1088 #endif