mlib update: new isnan()/isnanf() implementation
[tangerine.git] / compiler / mlib / k_standard.c
blobb6b67003ecdce6406c2b381d9cc4798bdbfbe119
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 #ifndef lint
14 static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_standard.c,v 1.5 1999/08/28 00:06:41 peter Exp $";
15 #endif
17 #include "math.h"
18 #include "math_private.h"
19 #include <errno.h>
21 #ifndef _USE_WRITE
22 #include <stdio.h> /* fputs(), stderr */
23 #define WRITE2(u,v) fputs(u, stderr)
24 #else /* !defined(_USE_WRITE) */
25 #include <unistd.h> /* write */
26 #define WRITE2(u,v) write(2, u, v)
27 #undef fflush
28 #endif /* !defined(_USE_WRITE) */
30 static const double zero = 0.0; /* used as const */
33 * Standard conformance (non-IEEE) on exception cases.
34 * Mapping:
35 * 1 -- acos(|x|>1)
36 * 2 -- asin(|x|>1)
37 * 3 -- atan2(+-0,+-0)
38 * 4 -- hypot overflow
39 * 5 -- cosh overflow
40 * 6 -- exp overflow
41 * 7 -- exp underflow
42 * 8 -- y0(0)
43 * 9 -- y0(-ve)
44 * 10-- y1(0)
45 * 11-- y1(-ve)
46 * 12-- yn(0)
47 * 13-- yn(-ve)
48 * 14-- lgamma(finite) overflow
49 * 15-- lgamma(-integer)
50 * 16-- log(0)
51 * 17-- log(x<0)
52 * 18-- log10(0)
53 * 19-- log10(x<0)
54 * 20-- pow(0.0,0.0)
55 * 21-- pow(x,y) overflow
56 * 22-- pow(x,y) underflow
57 * 23-- pow(0,negative)
58 * 24-- pow(neg,non-integral)
59 * 25-- sinh(finite) overflow
60 * 26-- sqrt(negative)
61 * 27-- fmod(x,0)
62 * 28-- remainder(x,0)
63 * 29-- acosh(x<1)
64 * 30-- atanh(|x|>1)
65 * 31-- atanh(|x|=1)
66 * 32-- scalb overflow
67 * 33-- scalb underflow
68 * 34-- j0(|x|>X_TLOSS)
69 * 35-- y0(x>X_TLOSS)
70 * 36-- j1(|x|>X_TLOSS)
71 * 37-- y1(x>X_TLOSS)
72 * 38-- jn(|x|>X_TLOSS, n)
73 * 39-- yn(x>X_TLOSS, n)
74 * 40-- gamma(finite) overflow
75 * 41-- gamma(-integer)
76 * 42-- pow(NaN,0.0)
80 double
81 __kernel_standard(double x, double y, int type)
83 struct exception exc;
84 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
85 #define HUGE_VAL inf
86 double inf = 0.0;
88 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
89 #endif
91 #ifdef _USE_WRITE
92 (void) fflush(stdout);
93 #endif
94 exc.arg1 = x;
95 exc.arg2 = y;
96 switch(type) {
97 case 1:
98 case 101:
99 /* acos(|x|>1) */
100 exc.type = DOMAIN;
101 exc.name = type < 100 ? "acos" : "acosf";
102 exc.retval = zero;
103 if (_LIB_VERSION == _POSIX_)
104 errno = EDOM;
105 else if (!matherr(&exc)) {
106 if(_LIB_VERSION == _SVID_) {
107 (void) WRITE2("acos: DOMAIN error\n", 19);
109 errno = EDOM;
111 break;
112 case 2:
113 case 102:
114 /* asin(|x|>1) */
115 exc.type = DOMAIN;
116 exc.name = type < 100 ? "asin" : "asinf";
117 exc.retval = zero;
118 if(_LIB_VERSION == _POSIX_)
119 errno = EDOM;
120 else if (!matherr(&exc)) {
121 if(_LIB_VERSION == _SVID_) {
122 (void) WRITE2("asin: DOMAIN error\n", 19);
124 errno = EDOM;
126 break;
127 case 3:
128 case 103:
129 /* atan2(+-0,+-0) */
130 exc.arg1 = y;
131 exc.arg2 = x;
132 exc.type = DOMAIN;
133 exc.name = type < 100 ? "atan2" : "atan2f";
134 exc.retval = zero;
135 if(_LIB_VERSION == _POSIX_)
136 errno = EDOM;
137 else if (!matherr(&exc)) {
138 if(_LIB_VERSION == _SVID_) {
139 (void) WRITE2("atan2: DOMAIN error\n", 20);
141 errno = EDOM;
143 break;
144 case 4:
145 case 104:
146 /* hypot(finite,finite) overflow */
147 exc.type = OVERFLOW;
148 exc.name = type < 100 ? "hypot" : "hypotf";
149 if (_LIB_VERSION == _SVID_)
150 exc.retval = HUGE;
151 else
152 exc.retval = HUGE_VAL;
153 if (_LIB_VERSION == _POSIX_)
154 errno = ERANGE;
155 else if (!matherr(&exc)) {
156 errno = ERANGE;
158 break;
159 case 5:
160 case 105:
161 /* cosh(finite) overflow */
162 exc.type = OVERFLOW;
163 exc.name = type < 100 ? "cosh" : "coshf";
164 if (_LIB_VERSION == _SVID_)
165 exc.retval = HUGE;
166 else
167 exc.retval = HUGE_VAL;
168 if (_LIB_VERSION == _POSIX_)
169 errno = ERANGE;
170 else if (!matherr(&exc)) {
171 errno = ERANGE;
173 break;
174 case 6:
175 case 106:
176 /* exp(finite) overflow */
177 exc.type = OVERFLOW;
178 exc.name = type < 100 ? "exp" : "expf";
179 if (_LIB_VERSION == _SVID_)
180 exc.retval = HUGE;
181 else
182 exc.retval = HUGE_VAL;
183 if (_LIB_VERSION == _POSIX_)
184 errno = ERANGE;
185 else if (!matherr(&exc)) {
186 errno = ERANGE;
188 break;
189 case 7:
190 case 107:
191 /* exp(finite) underflow */
192 exc.type = UNDERFLOW;
193 exc.name = type < 100 ? "exp" : "expf";
194 exc.retval = zero;
195 if (_LIB_VERSION == _POSIX_)
196 errno = ERANGE;
197 else if (!matherr(&exc)) {
198 errno = ERANGE;
200 break;
201 case 8:
202 case 108:
203 /* y0(0) = -inf */
204 exc.type = DOMAIN; /* should be SING for IEEE */
205 exc.name = type < 100 ? "y0" : "y0f";
206 if (_LIB_VERSION == _SVID_)
207 exc.retval = -HUGE;
208 else
209 exc.retval = -HUGE_VAL;
210 if (_LIB_VERSION == _POSIX_)
211 errno = EDOM;
212 else if (!matherr(&exc)) {
213 if (_LIB_VERSION == _SVID_) {
214 (void) WRITE2("y0: DOMAIN error\n", 17);
216 errno = EDOM;
218 break;
219 case 9:
220 case 109:
221 /* y0(x<0) = NaN */
222 exc.type = DOMAIN;
223 exc.name = type < 100 ? "y0" : "y0f";
224 if (_LIB_VERSION == _SVID_)
225 exc.retval = -HUGE;
226 else
227 exc.retval = -HUGE_VAL;
228 if (_LIB_VERSION == _POSIX_)
229 errno = EDOM;
230 else if (!matherr(&exc)) {
231 if (_LIB_VERSION == _SVID_) {
232 (void) WRITE2("y0: DOMAIN error\n", 17);
234 errno = EDOM;
236 break;
237 case 10:
238 case 110:
239 /* y1(0) = -inf */
240 exc.type = DOMAIN; /* should be SING for IEEE */
241 exc.name = type < 100 ? "y1" : "y1f";
242 if (_LIB_VERSION == _SVID_)
243 exc.retval = -HUGE;
244 else
245 exc.retval = -HUGE_VAL;
246 if (_LIB_VERSION == _POSIX_)
247 errno = EDOM;
248 else if (!matherr(&exc)) {
249 if (_LIB_VERSION == _SVID_) {
250 (void) WRITE2("y1: DOMAIN error\n", 17);
252 errno = EDOM;
254 break;
255 case 11:
256 case 111:
257 /* y1(x<0) = NaN */
258 exc.type = DOMAIN;
259 exc.name = type < 100 ? "y1" : "y1f";
260 if (_LIB_VERSION == _SVID_)
261 exc.retval = -HUGE;
262 else
263 exc.retval = -HUGE_VAL;
264 if (_LIB_VERSION == _POSIX_)
265 errno = EDOM;
266 else if (!matherr(&exc)) {
267 if (_LIB_VERSION == _SVID_) {
268 (void) WRITE2("y1: DOMAIN error\n", 17);
270 errno = EDOM;
272 break;
273 case 12:
274 case 112:
275 /* yn(n,0) = -inf */
276 exc.type = DOMAIN; /* should be SING for IEEE */
277 exc.name = type < 100 ? "yn" : "ynf";
278 if (_LIB_VERSION == _SVID_)
279 exc.retval = -HUGE;
280 else
281 exc.retval = -HUGE_VAL;
282 if (_LIB_VERSION == _POSIX_)
283 errno = EDOM;
284 else if (!matherr(&exc)) {
285 if (_LIB_VERSION == _SVID_) {
286 (void) WRITE2("yn: DOMAIN error\n", 17);
288 errno = EDOM;
290 break;
291 case 13:
292 case 113:
293 /* yn(x<0) = NaN */
294 exc.type = DOMAIN;
295 exc.name = type < 100 ? "yn" : "ynf";
296 if (_LIB_VERSION == _SVID_)
297 exc.retval = -HUGE;
298 else
299 exc.retval = -HUGE_VAL;
300 if (_LIB_VERSION == _POSIX_)
301 errno = EDOM;
302 else if (!matherr(&exc)) {
303 if (_LIB_VERSION == _SVID_) {
304 (void) WRITE2("yn: DOMAIN error\n", 17);
306 errno = EDOM;
308 break;
309 case 14:
310 case 114:
311 /* lgamma(finite) overflow */
312 exc.type = OVERFLOW;
313 exc.name = type < 100 ? "lgamma" : "lgammaf";
314 if (_LIB_VERSION == _SVID_)
315 exc.retval = HUGE;
316 else
317 exc.retval = HUGE_VAL;
318 if (_LIB_VERSION == _POSIX_)
319 errno = ERANGE;
320 else if (!matherr(&exc)) {
321 errno = ERANGE;
323 break;
324 case 15:
325 case 115:
326 /* lgamma(-integer) or lgamma(0) */
327 exc.type = SING;
328 exc.name = type < 100 ? "lgamma" : "lgammaf";
329 if (_LIB_VERSION == _SVID_)
330 exc.retval = HUGE;
331 else
332 exc.retval = HUGE_VAL;
333 if (_LIB_VERSION == _POSIX_)
334 errno = EDOM;
335 else if (!matherr(&exc)) {
336 if (_LIB_VERSION == _SVID_) {
337 (void) WRITE2("lgamma: SING error\n", 19);
339 errno = EDOM;
341 break;
342 case 16:
343 case 116:
344 /* log(0) */
345 exc.type = SING;
346 exc.name = type < 100 ? "log" : "logf";
347 if (_LIB_VERSION == _SVID_)
348 exc.retval = -HUGE;
349 else
350 exc.retval = -HUGE_VAL;
351 if (_LIB_VERSION == _POSIX_)
352 errno = ERANGE;
353 else if (!matherr(&exc)) {
354 if (_LIB_VERSION == _SVID_) {
355 (void) WRITE2("log: SING error\n", 16);
357 errno = EDOM;
359 break;
360 case 17:
361 case 117:
362 /* log(x<0) */
363 exc.type = DOMAIN;
364 exc.name = type < 100 ? "log" : "logf";
365 if (_LIB_VERSION == _SVID_)
366 exc.retval = -HUGE;
367 else
368 exc.retval = -HUGE_VAL;
369 if (_LIB_VERSION == _POSIX_)
370 errno = EDOM;
371 else if (!matherr(&exc)) {
372 if (_LIB_VERSION == _SVID_) {
373 (void) WRITE2("log: DOMAIN error\n", 18);
375 errno = EDOM;
377 break;
378 case 18:
379 case 118:
380 /* log10(0) */
381 exc.type = SING;
382 exc.name = type < 100 ? "log10" : "log10f";
383 if (_LIB_VERSION == _SVID_)
384 exc.retval = -HUGE;
385 else
386 exc.retval = -HUGE_VAL;
387 if (_LIB_VERSION == _POSIX_)
388 errno = ERANGE;
389 else if (!matherr(&exc)) {
390 if (_LIB_VERSION == _SVID_) {
391 (void) WRITE2("log10: SING error\n", 18);
393 errno = EDOM;
395 break;
396 case 19:
397 case 119:
398 /* log10(x<0) */
399 exc.type = DOMAIN;
400 exc.name = type < 100 ? "log10" : "log10f";
401 if (_LIB_VERSION == _SVID_)
402 exc.retval = -HUGE;
403 else
404 exc.retval = -HUGE_VAL;
405 if (_LIB_VERSION == _POSIX_)
406 errno = EDOM;
407 else if (!matherr(&exc)) {
408 if (_LIB_VERSION == _SVID_) {
409 (void) WRITE2("log10: DOMAIN error\n", 20);
411 errno = EDOM;
413 break;
414 case 20:
415 case 120:
416 /* pow(0.0,0.0) */
417 /* error only if _LIB_VERSION == _SVID_ */
418 exc.type = DOMAIN;
419 exc.name = type < 100 ? "pow" : "powf";
420 exc.retval = zero;
421 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
422 else if (!matherr(&exc)) {
423 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
424 errno = EDOM;
426 break;
427 case 21:
428 case 121:
429 /* pow(x,y) overflow */
430 exc.type = OVERFLOW;
431 exc.name = type < 100 ? "pow" : "powf";
432 if (_LIB_VERSION == _SVID_) {
433 exc.retval = HUGE;
434 y *= 0.5;
435 if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
436 } else {
437 exc.retval = HUGE_VAL;
438 y *= 0.5;
439 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
441 if (_LIB_VERSION == _POSIX_)
442 errno = ERANGE;
443 else if (!matherr(&exc)) {
444 errno = ERANGE;
446 break;
447 case 22:
448 case 122:
449 /* pow(x,y) underflow */
450 exc.type = UNDERFLOW;
451 exc.name = type < 100 ? "pow" : "powf";
452 exc.retval = zero;
453 if (_LIB_VERSION == _POSIX_)
454 errno = ERANGE;
455 else if (!matherr(&exc)) {
456 errno = ERANGE;
458 break;
459 case 23:
460 case 123:
461 /* 0**neg */
462 exc.type = DOMAIN;
463 exc.name = type < 100 ? "pow" : "powf";
464 if (_LIB_VERSION == _SVID_)
465 exc.retval = zero;
466 else
467 exc.retval = -HUGE_VAL;
468 if (_LIB_VERSION == _POSIX_)
469 errno = EDOM;
470 else if (!matherr(&exc)) {
471 if (_LIB_VERSION == _SVID_) {
472 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
474 errno = EDOM;
476 break;
477 case 24:
478 case 124:
479 /* neg**non-integral */
480 exc.type = DOMAIN;
481 exc.name = type < 100 ? "pow" : "powf";
482 if (_LIB_VERSION == _SVID_)
483 exc.retval = zero;
484 else
485 exc.retval = zero/zero; /* X/Open allow NaN */
486 if (_LIB_VERSION == _POSIX_)
487 errno = EDOM;
488 else if (!matherr(&exc)) {
489 if (_LIB_VERSION == _SVID_) {
490 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
492 errno = EDOM;
494 break;
495 case 25:
496 case 125:
497 /* sinh(finite) overflow */
498 exc.type = OVERFLOW;
499 exc.name = type < 100 ? "sinh" : "sinhf";
500 if (_LIB_VERSION == _SVID_)
501 exc.retval = ( (x>zero) ? HUGE : -HUGE);
502 else
503 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
504 if (_LIB_VERSION == _POSIX_)
505 errno = ERANGE;
506 else if (!matherr(&exc)) {
507 errno = ERANGE;
509 break;
510 case 26:
511 case 126:
512 /* sqrt(x<0) */
513 exc.type = DOMAIN;
514 exc.name = type < 100 ? "sqrt" : "sqrtf";
515 if (_LIB_VERSION == _SVID_)
516 exc.retval = zero;
517 else
518 exc.retval = zero/zero;
519 if (_LIB_VERSION == _POSIX_)
520 errno = EDOM;
521 else if (!matherr(&exc)) {
522 if (_LIB_VERSION == _SVID_) {
523 (void) WRITE2("sqrt: DOMAIN error\n", 19);
525 errno = EDOM;
527 break;
528 case 27:
529 case 127:
530 /* fmod(x,0) */
531 exc.type = DOMAIN;
532 exc.name = type < 100 ? "fmod" : "fmodf";
533 if (_LIB_VERSION == _SVID_)
534 exc.retval = x;
535 else
536 exc.retval = zero/zero;
537 if (_LIB_VERSION == _POSIX_)
538 errno = EDOM;
539 else if (!matherr(&exc)) {
540 if (_LIB_VERSION == _SVID_) {
541 (void) WRITE2("fmod: DOMAIN error\n", 20);
543 errno = EDOM;
545 break;
546 case 28:
547 case 128:
548 /* remainder(x,0) */
549 exc.type = DOMAIN;
550 exc.name = type < 100 ? "remainder" : "remainderf";
551 exc.retval = zero/zero;
552 if (_LIB_VERSION == _POSIX_)
553 errno = EDOM;
554 else if (!matherr(&exc)) {
555 if (_LIB_VERSION == _SVID_) {
556 (void) WRITE2("remainder: DOMAIN error\n", 24);
558 errno = EDOM;
560 break;
561 case 29:
562 case 129:
563 /* acosh(x<1) */
564 exc.type = DOMAIN;
565 exc.name = type < 100 ? "acosh" : "acoshf";
566 exc.retval = zero/zero;
567 if (_LIB_VERSION == _POSIX_)
568 errno = EDOM;
569 else if (!matherr(&exc)) {
570 if (_LIB_VERSION == _SVID_) {
571 (void) WRITE2("acosh: DOMAIN error\n", 20);
573 errno = EDOM;
575 break;
576 case 30:
577 case 130:
578 /* atanh(|x|>1) */
579 exc.type = DOMAIN;
580 exc.name = type < 100 ? "atanh" : "atanhf";
581 exc.retval = zero/zero;
582 if (_LIB_VERSION == _POSIX_)
583 errno = EDOM;
584 else if (!matherr(&exc)) {
585 if (_LIB_VERSION == _SVID_) {
586 (void) WRITE2("atanh: DOMAIN error\n", 20);
588 errno = EDOM;
590 break;
591 case 31:
592 case 131:
593 /* atanh(|x|=1) */
594 exc.type = SING;
595 exc.name = type < 100 ? "atanh" : "atanhf";
596 exc.retval = x/zero; /* sign(x)*inf */
597 if (_LIB_VERSION == _POSIX_)
598 errno = EDOM;
599 else if (!matherr(&exc)) {
600 if (_LIB_VERSION == _SVID_) {
601 (void) WRITE2("atanh: SING error\n", 18);
603 errno = EDOM;
605 break;
606 case 32:
607 case 132:
608 /* scalb overflow; SVID also returns +-HUGE_VAL */
609 exc.type = OVERFLOW;
610 exc.name = type < 100 ? "scalb" : "scalbf";
611 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
612 if (_LIB_VERSION == _POSIX_)
613 errno = ERANGE;
614 else if (!matherr(&exc)) {
615 errno = ERANGE;
617 break;
618 case 33:
619 case 133:
620 /* scalb underflow */
621 exc.type = UNDERFLOW;
622 exc.name = type < 100 ? "scalb" : "scalbf";
623 exc.retval = copysign(zero,x);
624 if (_LIB_VERSION == _POSIX_)
625 errno = ERANGE;
626 else if (!matherr(&exc)) {
627 errno = ERANGE;
629 break;
630 case 34:
631 case 134:
632 /* j0(|x|>X_TLOSS) */
633 exc.type = TLOSS;
634 exc.name = type < 100 ? "j0" : "j0f";
635 exc.retval = zero;
636 if (_LIB_VERSION == _POSIX_)
637 errno = ERANGE;
638 else if (!matherr(&exc)) {
639 if (_LIB_VERSION == _SVID_) {
640 (void) WRITE2(exc.name, 2);
641 (void) WRITE2(": TLOSS error\n", 14);
643 errno = ERANGE;
645 break;
646 case 35:
647 case 135:
648 /* y0(x>X_TLOSS) */
649 exc.type = TLOSS;
650 exc.name = type < 100 ? "y0" : "y0f";
651 exc.retval = zero;
652 if (_LIB_VERSION == _POSIX_)
653 errno = ERANGE;
654 else if (!matherr(&exc)) {
655 if (_LIB_VERSION == _SVID_) {
656 (void) WRITE2(exc.name, 2);
657 (void) WRITE2(": TLOSS error\n", 14);
659 errno = ERANGE;
661 break;
662 case 36:
663 case 136:
664 /* j1(|x|>X_TLOSS) */
665 exc.type = TLOSS;
666 exc.name = type < 100 ? "j1" : "j1f";
667 exc.retval = zero;
668 if (_LIB_VERSION == _POSIX_)
669 errno = ERANGE;
670 else if (!matherr(&exc)) {
671 if (_LIB_VERSION == _SVID_) {
672 (void) WRITE2(exc.name, 2);
673 (void) WRITE2(": TLOSS error\n", 14);
675 errno = ERANGE;
677 break;
678 case 37:
679 case 137:
680 /* y1(x>X_TLOSS) */
681 exc.type = TLOSS;
682 exc.name = type < 100 ? "y1" : "y1f";
683 exc.retval = zero;
684 if (_LIB_VERSION == _POSIX_)
685 errno = ERANGE;
686 else if (!matherr(&exc)) {
687 if (_LIB_VERSION == _SVID_) {
688 (void) WRITE2(exc.name, 2);
689 (void) WRITE2(": TLOSS error\n", 14);
691 errno = ERANGE;
693 break;
694 case 38:
695 case 138:
696 /* jn(|x|>X_TLOSS) */
697 exc.type = TLOSS;
698 exc.name = type < 100 ? "jn" : "jnf";
699 exc.retval = zero;
700 if (_LIB_VERSION == _POSIX_)
701 errno = ERANGE;
702 else if (!matherr(&exc)) {
703 if (_LIB_VERSION == _SVID_) {
704 (void) WRITE2(exc.name, 2);
705 (void) WRITE2(": TLOSS error\n", 14);
707 errno = ERANGE;
709 break;
710 case 39:
711 case 139:
712 /* yn(x>X_TLOSS) */
713 exc.type = TLOSS;
714 exc.name = type < 100 ? "yn" : "ynf";
715 exc.retval = zero;
716 if (_LIB_VERSION == _POSIX_)
717 errno = ERANGE;
718 else if (!matherr(&exc)) {
719 if (_LIB_VERSION == _SVID_) {
720 (void) WRITE2(exc.name, 2);
721 (void) WRITE2(": TLOSS error\n", 14);
723 errno = ERANGE;
725 break;
726 case 40:
727 case 140:
728 /* gamma(finite) overflow */
729 exc.type = OVERFLOW;
730 exc.name = type < 100 ? "gamma" : "gammaf";
731 if (_LIB_VERSION == _SVID_)
732 exc.retval = HUGE;
733 else
734 exc.retval = HUGE_VAL;
735 if (_LIB_VERSION == _POSIX_)
736 errno = ERANGE;
737 else if (!matherr(&exc)) {
738 errno = ERANGE;
740 break;
741 case 41:
742 case 141:
743 /* gamma(-integer) or gamma(0) */
744 exc.type = SING;
745 exc.name = type < 100 ? "gamma" : "gammaf";
746 if (_LIB_VERSION == _SVID_)
747 exc.retval = HUGE;
748 else
749 exc.retval = HUGE_VAL;
750 if (_LIB_VERSION == _POSIX_)
751 errno = EDOM;
752 else if (!matherr(&exc)) {
753 if (_LIB_VERSION == _SVID_) {
754 (void) WRITE2("gamma: SING error\n", 18);
756 errno = EDOM;
758 break;
759 case 42:
760 case 142:
761 /* pow(NaN,0.0) */
762 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
763 exc.type = DOMAIN;
764 exc.name = type < 100 ? "pow" : "powf";
765 exc.retval = x;
766 if (_LIB_VERSION == _IEEE_ ||
767 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
768 else if (!matherr(&exc)) {
769 errno = EDOM;
771 break;
773 return exc.retval;