2 /* @(#)k_standard.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
19 #include <stdio.h> /* fputs(), stderr */
20 #define WRITE2(u,v) fputs(u, stderr)
21 #else /* !defined(_USE_WRITE) */
22 #include <unistd.h> /* write */
23 #define WRITE2(u,v) write(2, u, v)
25 #endif /* !defined(_USE_WRITE) */
28 static const double zero
= 0.0; /* used as const */
30 static double zero
= 0.0; /* used as const */
34 * Standard conformance (non-IEEE) on exception cases.
49 * 14-- lgamma(finite) overflow
50 * 15-- lgamma(-integer)
56 * 21-- pow(x,y) overflow
57 * 22-- pow(x,y) underflow
58 * 23-- pow(0,negative)
59 * 24-- pow(neg,non-integral)
60 * 25-- sinh(finite) overflow
68 * 33-- scalb underflow
69 * 34-- j0(|x|>X_TLOSS)
71 * 36-- j1(|x|>X_TLOSS)
73 * 38-- jn(|x|>X_TLOSS, n)
74 * 39-- yn(x>X_TLOSS, n)
75 * 40-- gamma(finite) overflow
76 * 41-- gamma(-integer)
82 double __kernel_standard(double x
, double y
, int type
)
84 double __kernel_standard(x
,y
,type
)
89 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
93 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
97 /* (void) fflush(_stdout_r(p)); */
107 exc
.name
= type
< 100 ? "acos" : "acosf";
109 if (_LIB_VERSION
== _POSIX_
)
111 else if (!matherr(&exc
)) {
112 /* if(_LIB_VERSION == _SVID_) {
113 (void) WRITE2("acos: DOMAIN error\n", 19);
122 exc
.name
= type
< 100 ? "asin" : "asinf";
124 if(_LIB_VERSION
== _POSIX_
)
126 else if (!matherr(&exc
)) {
127 /* if(_LIB_VERSION == _SVID_) {
128 (void) WRITE2("asin: DOMAIN error\n", 19);
139 exc
.name
= type
< 100 ? "atan2" : "atan2f";
141 if(_LIB_VERSION
== _POSIX_
)
143 else if (!matherr(&exc
)) {
144 /* if(_LIB_VERSION == _SVID_) {
145 (void) WRITE2("atan2: DOMAIN error\n", 20);
152 /* hypot(finite,finite) overflow */
154 exc
.name
= type
< 100 ? "hypot" : "hypotf";
155 if (_LIB_VERSION
== _SVID_
)
158 exc
.retval
= HUGE_VAL
;
159 if (_LIB_VERSION
== _POSIX_
)
161 else if (!matherr(&exc
)) {
167 /* cosh(finite) overflow */
169 exc
.name
= type
< 100 ? "cosh" : "coshf";
170 if (_LIB_VERSION
== _SVID_
)
173 exc
.retval
= HUGE_VAL
;
174 if (_LIB_VERSION
== _POSIX_
)
176 else if (!matherr(&exc
)) {
182 /* exp(finite) overflow */
184 exc
.name
= type
< 100 ? "exp" : "expf";
185 if (_LIB_VERSION
== _SVID_
)
188 exc
.retval
= HUGE_VAL
;
189 if (_LIB_VERSION
== _POSIX_
)
191 else if (!matherr(&exc
)) {
197 /* exp(finite) underflow */
198 exc
.type
= UNDERFLOW
;
199 exc
.name
= type
< 100 ? "exp" : "expf";
201 if (_LIB_VERSION
== _POSIX_
)
203 else if (!matherr(&exc
)) {
210 exc
.type
= DOMAIN
; /* should be SING for IEEE */
211 exc
.name
= type
< 100 ? "y0" : "y0f";
212 if (_LIB_VERSION
== _SVID_
)
215 exc
.retval
= -HUGE_VAL
;
216 if (_LIB_VERSION
== _POSIX_
)
218 else if (!matherr(&exc
)) {
219 /* if (_LIB_VERSION == _SVID_) {
220 (void) WRITE2("y0: DOMAIN error\n", 17);
229 exc
.name
= type
< 100 ? "y0" : "y0f";
230 if (_LIB_VERSION
== _SVID_
)
233 exc
.retval
= -HUGE_VAL
;
234 if (_LIB_VERSION
== _POSIX_
)
236 else if (!matherr(&exc
)) {
237 /*if (_LIB_VERSION == _SVID_) {
238 (void) WRITE2("y0: DOMAIN error\n", 17);
246 exc
.type
= DOMAIN
; /* should be SING for IEEE */
247 exc
.name
= type
< 100 ? "y1" : "y1f";
248 if (_LIB_VERSION
== _SVID_
)
251 exc
.retval
= -HUGE_VAL
;
252 if (_LIB_VERSION
== _POSIX_
)
254 else if (!matherr(&exc
)) {
255 /* if (_LIB_VERSION == _SVID_) {
256 (void) WRITE2("y1: DOMAIN error\n", 17);
265 exc
.name
= type
< 100 ? "y1" : "y1f";
266 if (_LIB_VERSION
== _SVID_
)
269 exc
.retval
= -HUGE_VAL
;
270 if (_LIB_VERSION
== _POSIX_
)
272 else if (!matherr(&exc
)) {
273 /* if (_LIB_VERSION == _SVID_) {
274 (void) WRITE2("y1: DOMAIN error\n", 17);
282 exc
.type
= DOMAIN
; /* should be SING for IEEE */
283 exc
.name
= type
< 100 ? "yn" : "ynf";
284 if (_LIB_VERSION
== _SVID_
)
287 exc
.retval
= -HUGE_VAL
;
288 if (_LIB_VERSION
== _POSIX_
)
290 else if (!matherr(&exc
)) {
291 /* if (_LIB_VERSION == _SVID_) {
292 (void) WRITE2("yn: DOMAIN error\n", 17);
301 exc
.name
= type
< 100 ? "yn" : "ynf";
302 if (_LIB_VERSION
== _SVID_
)
305 exc
.retval
= -HUGE_VAL
;
306 if (_LIB_VERSION
== _POSIX_
)
308 else if (!matherr(&exc
)) {
309 /* if (_LIB_VERSION == _SVID_) {
310 (void) WRITE2("yn: DOMAIN error\n", 17);
317 /* lgamma(finite) overflow */
319 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
320 if (_LIB_VERSION
== _SVID_
)
323 exc
.retval
= HUGE_VAL
;
324 if (_LIB_VERSION
== _POSIX_
)
326 else if (!matherr(&exc
)) {
332 /* lgamma(-integer) or lgamma(0) */
334 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
335 if (_LIB_VERSION
== _SVID_
)
338 exc
.retval
= HUGE_VAL
;
339 if (_LIB_VERSION
== _POSIX_
)
341 else if (!matherr(&exc
)) {
342 /* if (_LIB_VERSION == _SVID_) {
343 (void) WRITE2("lgamma: SING error\n", 19);
352 exc
.name
= type
< 100 ? "log" : "logf";
353 if (_LIB_VERSION
== _SVID_
)
356 exc
.retval
= -HUGE_VAL
;
357 if (_LIB_VERSION
== _POSIX_
)
359 else if (!matherr(&exc
)) {
360 /* if (_LIB_VERSION == _SVID_) {
361 (void) WRITE2("log: SING error\n", 16);
370 exc
.name
= type
< 100 ? "log" : "logf";
371 if (_LIB_VERSION
== _SVID_
)
374 exc
.retval
= -HUGE_VAL
;
375 if (_LIB_VERSION
== _POSIX_
)
377 else if (!matherr(&exc
)) {
378 /* if (_LIB_VERSION == _SVID_) {
379 (void) WRITE2("log: DOMAIN error\n", 18);
388 exc
.name
= type
< 100 ? "log10" : "log10f";
389 if (_LIB_VERSION
== _SVID_
)
392 exc
.retval
= -HUGE_VAL
;
393 if (_LIB_VERSION
== _POSIX_
)
395 else if (!matherr(&exc
)) {
396 /* if (_LIB_VERSION == _SVID_) {
397 (void) WRITE2("log10: SING error\n", 18);
406 exc
.name
= type
< 100 ? "log10" : "log10f";
407 if (_LIB_VERSION
== _SVID_
)
410 exc
.retval
= -HUGE_VAL
;
411 if (_LIB_VERSION
== _POSIX_
)
413 else if (!matherr(&exc
)) {
414 /* if (_LIB_VERSION == _SVID_) {
415 (void) WRITE2("log10: DOMAIN error\n", 20);
423 /* error only if _LIB_VERSION == _SVID_ */
425 exc
.name
= type
< 100 ? "pow" : "powf";
427 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
428 else if (!matherr(&exc
)) {
429 /* (void) WRITE2("pow(0,0): DOMAIN error\n", 23); */
435 /* pow(x,y) overflow */
437 exc
.name
= type
< 100 ? "pow" : "powf";
438 if (_LIB_VERSION
== _SVID_
) {
441 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE
;
443 exc
.retval
= HUGE_VAL
;
445 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
447 if (_LIB_VERSION
== _POSIX_
)
449 else if (!matherr(&exc
)) {
455 /* pow(x,y) underflow */
456 exc
.type
= UNDERFLOW
;
457 exc
.name
= type
< 100 ? "pow" : "powf";
459 if (_LIB_VERSION
== _POSIX_
)
461 else if (!matherr(&exc
)) {
469 exc
.name
= type
< 100 ? "pow" : "powf";
470 if (_LIB_VERSION
== _SVID_
)
473 exc
.retval
= -HUGE_VAL
;
474 if (_LIB_VERSION
== _POSIX_
)
476 else if (!matherr(&exc
)) {
477 /* if (_LIB_VERSION == _SVID_) {
478 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
485 /* neg**non-integral */
487 exc
.name
= type
< 100 ? "pow" : "powf";
488 if (_LIB_VERSION
== _SVID_
)
491 exc
.retval
= zero
/zero
; /* X/Open allow NaN */
492 if (_LIB_VERSION
== _POSIX_
)
494 else if (!matherr(&exc
)) {
495 /* if (_LIB_VERSION == _SVID_) {
496 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
503 /* sinh(finite) overflow */
505 exc
.name
= type
< 100 ? "sinh" : "sinhf";
506 if (_LIB_VERSION
== _SVID_
)
507 exc
.retval
= ( (x
>zero
) ? HUGE
: -HUGE
);
509 exc
.retval
= ( (x
>zero
) ? HUGE_VAL
: -HUGE_VAL
);
510 if (_LIB_VERSION
== _POSIX_
)
512 else if (!matherr(&exc
)) {
520 exc
.name
= type
< 100 ? "sqrt" : "sqrtf";
521 if (_LIB_VERSION
== _SVID_
)
524 exc
.retval
= zero
/zero
;
525 if (_LIB_VERSION
== _POSIX_
)
527 else if (!matherr(&exc
)) {
528 /* if (_LIB_VERSION == _SVID_) {
529 (void) WRITE2("sqrt: DOMAIN error\n", 19);
538 exc
.name
= type
< 100 ? "fmod" : "fmodf";
539 if (_LIB_VERSION
== _SVID_
)
542 exc
.retval
= zero
/zero
;
543 if (_LIB_VERSION
== _POSIX_
)
545 else if (!matherr(&exc
)) {
546 /* if (_LIB_VERSION == _SVID_) {
547 (void) WRITE2("fmod: DOMAIN error\n", 20);
556 exc
.name
= type
< 100 ? "remainder" : "remainderf";
557 exc
.retval
= zero
/zero
;
558 if (_LIB_VERSION
== _POSIX_
)
560 else if (!matherr(&exc
)) {
561 /* if (_LIB_VERSION == _SVID_) {
562 (void) WRITE2("remainder: DOMAIN error\n", 24);
571 exc
.name
= type
< 100 ? "acosh" : "acoshf";
572 exc
.retval
= zero
/zero
;
573 if (_LIB_VERSION
== _POSIX_
)
575 else if (!matherr(&exc
)) {
576 /* if (_LIB_VERSION == _SVID_) {
577 (void) WRITE2("acosh: DOMAIN error\n", 20);
586 exc
.name
= type
< 100 ? "atanh" : "atanhf";
587 exc
.retval
= zero
/zero
;
588 if (_LIB_VERSION
== _POSIX_
)
590 else if (!matherr(&exc
)) {
591 /* if (_LIB_VERSION == _SVID_) {
592 (void) WRITE2("atanh: DOMAIN error\n", 20);
601 exc
.name
= type
< 100 ? "atanh" : "atanhf";
602 exc
.retval
= x
/zero
; /* sign(x)*inf */
603 if (_LIB_VERSION
== _POSIX_
)
605 else if (!matherr(&exc
)) {
606 /* if (_LIB_VERSION == _SVID_) {
607 (void) WRITE2("atanh: SING error\n", 18);
614 /* scalb overflow; SVID also returns +-HUGE_VAL */
616 exc
.name
= type
< 100 ? "scalb" : "scalbf";
617 exc
.retval
= x
> zero
? HUGE_VAL
: -HUGE_VAL
;
618 if (_LIB_VERSION
== _POSIX_
)
620 else if (!matherr(&exc
)) {
626 /* scalb underflow */
627 exc
.type
= UNDERFLOW
;
628 exc
.name
= type
< 100 ? "scalb" : "scalbf";
629 exc
.retval
= copysign(zero
,x
);
630 if (_LIB_VERSION
== _POSIX_
)
632 else if (!matherr(&exc
)) {
638 /* j0(|x|>X_TLOSS) */
640 exc
.name
= type
< 100 ? "j0" : "j0f";
642 if (_LIB_VERSION
== _POSIX_
)
644 else if (!matherr(&exc
)) {
645 /* if (_LIB_VERSION == _SVID_) {
646 (void) WRITE2(exc.name, 2);
647 (void) WRITE2(": TLOSS error\n", 14);
656 exc
.name
= type
< 100 ? "y0" : "y0f";
658 if (_LIB_VERSION
== _POSIX_
)
660 else if (!matherr(&exc
)) {
661 /* if (_LIB_VERSION == _SVID_) {
662 (void) WRITE2(exc.name, 2);
663 (void) WRITE2(": TLOSS error\n", 14);
670 /* j1(|x|>X_TLOSS) */
672 exc
.name
= type
< 100 ? "j1" : "j1f";
674 if (_LIB_VERSION
== _POSIX_
)
676 else if (!matherr(&exc
)) {
677 /* if (_LIB_VERSION == _SVID_) {
678 (void) WRITE2(exc.name, 2);
679 (void) WRITE2(": TLOSS error\n", 14);
688 exc
.name
= type
< 100 ? "y1" : "y1f";
690 if (_LIB_VERSION
== _POSIX_
)
692 else if (!matherr(&exc
)) {
693 /* if (_LIB_VERSION == _SVID_) {
694 (void) WRITE2(exc.name, 2);
695 (void) WRITE2(": TLOSS error\n", 14);
702 /* jn(|x|>X_TLOSS) */
704 exc
.name
= type
< 100 ? "jn" : "jnf";
706 if (_LIB_VERSION
== _POSIX_
)
708 else if (!matherr(&exc
)) {
709 /* if (_LIB_VERSION == _SVID_) {
710 (void) WRITE2(exc.name, 2);
711 (void) WRITE2(": TLOSS error\n", 14);
720 exc
.name
= type
< 100 ? "yn" : "ynf";
722 if (_LIB_VERSION
== _POSIX_
)
724 else if (!matherr(&exc
)) {
725 /* if (_LIB_VERSION == _SVID_) {
726 (void) WRITE2(exc.name, 2);
727 (void) WRITE2(": TLOSS error\n", 14);
734 /* gamma(finite) overflow */
736 exc
.name
= type
< 100 ? "gamma" : "gammaf";
737 if (_LIB_VERSION
== _SVID_
)
740 exc
.retval
= HUGE_VAL
;
741 if (_LIB_VERSION
== _POSIX_
)
743 else if (!matherr(&exc
)) {
749 /* gamma(-integer) or gamma(0) */
751 exc
.name
= type
< 100 ? "gamma" : "gammaf";
752 if (_LIB_VERSION
== _SVID_
)
755 exc
.retval
= HUGE_VAL
;
756 if (_LIB_VERSION
== _POSIX_
)
758 else if (!matherr(&exc
)) {
759 /* if (_LIB_VERSION == _SVID_) {
760 (void) WRITE2("gamma: SING error\n", 18);
768 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
770 exc
.name
= type
< 100 ? "pow" : "powf";
772 if (_LIB_VERSION
== _IEEE_
||
773 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
774 else if (!matherr(&exc
)) {