1 /* @(#)k_standard.c 5.1 93/09/24 */
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
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 $";
18 #include "math_private.h"
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)
28 #endif /* !defined(_USE_WRITE) */
31 static const double zero
= 0.0; /* used as const */
33 static double zero
= 0.0; /* used as const */
37 * Standard conformance (non-IEEE) on exception cases.
52 * 14-- lgamma(finite) overflow
53 * 15-- lgamma(-integer)
59 * 21-- pow(x,y) overflow
60 * 22-- pow(x,y) underflow
61 * 23-- pow(0,negative)
62 * 24-- pow(neg,non-integral)
63 * 25-- sinh(finite) overflow
71 * 33-- scalb underflow
72 * 34-- j0(|x|>X_TLOSS)
74 * 36-- j1(|x|>X_TLOSS)
76 * 38-- jn(|x|>X_TLOSS, n)
77 * 39-- yn(x>X_TLOSS, n)
78 * 40-- gamma(finite) overflow
79 * 41-- gamma(-integer)
85 double __kernel_standard(double x
, double y
, int type
)
87 double __kernel_standard(x
,y
,type
)
92 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
96 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
100 (void) fflush(stdout
);
110 exc
.name
= type
< 100 ? "acos" : (type
< 200
111 ? "acosf" : "acosl");;
113 if (_LIB_VERSION
== _POSIX_
)
115 else if (!matherr(&exc
)) {
116 if(_LIB_VERSION
== _SVID_
) {
117 (void) WRITE2("acos: DOMAIN error\n", 19);
127 exc
.name
= type
< 100 ? "asin" : (type
< 200
128 ? "asinf" : "asinl");
130 if(_LIB_VERSION
== _POSIX_
)
132 else if (!matherr(&exc
)) {
133 if(_LIB_VERSION
== _SVID_
) {
134 (void) WRITE2("asin: DOMAIN error\n", 19);
146 exc
.name
= type
< 100 ? "atan2" : (type
< 200
147 ? "atan2f" : "atan2l");
149 if(_LIB_VERSION
== _POSIX_
)
151 else if (!matherr(&exc
)) {
152 if(_LIB_VERSION
== _SVID_
) {
153 (void) WRITE2("atan2: DOMAIN error\n", 20);
161 /* hypot(finite,finite) overflow */
163 exc
.name
= type
< 100 ? "hypot" : (type
< 200
164 ? "hypotf" : "hypotl");
165 if (_LIB_VERSION
== _SVID_
)
168 exc
.retval
= HUGE_VAL
;
169 if (_LIB_VERSION
== _POSIX_
)
171 else if (!matherr(&exc
)) {
178 /* cosh(finite) overflow */
180 exc
.name
= type
< 100 ? "cosh" : (type
< 200
181 ? "coshf" : "coshl");
182 if (_LIB_VERSION
== _SVID_
)
185 exc
.retval
= HUGE_VAL
;
186 if (_LIB_VERSION
== _POSIX_
)
188 else if (!matherr(&exc
)) {
195 /* exp(finite) overflow */
197 exc
.name
= type
< 100 ? "exp" : (type
< 200
199 if (_LIB_VERSION
== _SVID_
)
202 exc
.retval
= HUGE_VAL
;
203 if (_LIB_VERSION
== _POSIX_
)
205 else if (!matherr(&exc
)) {
212 /* exp(finite) underflow */
213 exc
.type
= UNDERFLOW
;
214 exc
.name
= type
< 100 ? "exp" : (type
< 200
217 if (_LIB_VERSION
== _POSIX_
)
219 else if (!matherr(&exc
)) {
227 exc
.type
= DOMAIN
; /* should be SING for IEEE */
228 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
229 if (_LIB_VERSION
== _SVID_
)
232 exc
.retval
= -HUGE_VAL
;
233 if (_LIB_VERSION
== _POSIX_
)
235 else if (!matherr(&exc
)) {
236 if (_LIB_VERSION
== _SVID_
) {
237 (void) WRITE2("y0: DOMAIN error\n", 17);
247 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
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("y0: DOMAIN error\n", 17);
265 exc
.type
= DOMAIN
; /* should be SING for IEEE */
266 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
267 if (_LIB_VERSION
== _SVID_
)
270 exc
.retval
= -HUGE_VAL
;
271 if (_LIB_VERSION
== _POSIX_
)
273 else if (!matherr(&exc
)) {
274 if (_LIB_VERSION
== _SVID_
) {
275 (void) WRITE2("y1: DOMAIN error\n", 17);
285 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
286 if (_LIB_VERSION
== _SVID_
)
289 exc
.retval
= -HUGE_VAL
;
290 if (_LIB_VERSION
== _POSIX_
)
292 else if (!matherr(&exc
)) {
293 if (_LIB_VERSION
== _SVID_
) {
294 (void) WRITE2("y1: DOMAIN error\n", 17);
303 exc
.type
= DOMAIN
; /* should be SING for IEEE */
304 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
305 if (_LIB_VERSION
== _SVID_
)
308 exc
.retval
= -HUGE_VAL
;
309 if (_LIB_VERSION
== _POSIX_
)
311 else if (!matherr(&exc
)) {
312 if (_LIB_VERSION
== _SVID_
) {
313 (void) WRITE2("yn: DOMAIN error\n", 17);
323 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
324 if (_LIB_VERSION
== _SVID_
)
327 exc
.retval
= -HUGE_VAL
;
328 if (_LIB_VERSION
== _POSIX_
)
330 else if (!matherr(&exc
)) {
331 if (_LIB_VERSION
== _SVID_
) {
332 (void) WRITE2("yn: DOMAIN error\n", 17);
340 /* lgamma(finite) overflow */
342 exc
.name
= type
< 100 ? "lgamma" : (type
< 200
343 ? "lgammaf" : "lgammal");
344 if (_LIB_VERSION
== _SVID_
)
347 exc
.retval
= HUGE_VAL
;
348 if (_LIB_VERSION
== _POSIX_
)
350 else if (!matherr(&exc
)) {
357 /* lgamma(-integer) or lgamma(0) */
359 exc
.name
= type
< 100 ? "lgamma" : (type
< 200
360 ? "lgammaf" : "lgammal");
361 if (_LIB_VERSION
== _SVID_
)
364 exc
.retval
= HUGE_VAL
;
365 if (_LIB_VERSION
== _POSIX_
)
367 else if (!matherr(&exc
)) {
368 if (_LIB_VERSION
== _SVID_
) {
369 (void) WRITE2("lgamma: SING error\n", 19);
379 exc
.name
= type
< 100 ? "log" : (type
< 200 ? "logf" : "logl");
380 if (_LIB_VERSION
== _SVID_
)
383 exc
.retval
= -HUGE_VAL
;
384 if (_LIB_VERSION
== _POSIX_
)
386 else if (!matherr(&exc
)) {
387 if (_LIB_VERSION
== _SVID_
) {
388 (void) WRITE2("log: SING error\n", 16);
398 exc
.name
= type
< 100 ? "log" : (type
< 200 ? "logf" : "logl");
399 if (_LIB_VERSION
== _SVID_
)
402 exc
.retval
= -HUGE_VAL
;
403 if (_LIB_VERSION
== _POSIX_
)
405 else if (!matherr(&exc
)) {
406 if (_LIB_VERSION
== _SVID_
) {
407 (void) WRITE2("log: DOMAIN error\n", 18);
417 exc
.name
= type
< 100 ? "log10" : (type
< 200
418 ? "log10f" : "log10l");
419 if (_LIB_VERSION
== _SVID_
)
422 exc
.retval
= -HUGE_VAL
;
423 if (_LIB_VERSION
== _POSIX_
)
425 else if (!matherr(&exc
)) {
426 if (_LIB_VERSION
== _SVID_
) {
427 (void) WRITE2("log10: SING error\n", 18);
437 exc
.name
= type
< 100 ? "log10" : (type
< 200
438 ? "log10f" : "log10l");
439 if (_LIB_VERSION
== _SVID_
)
442 exc
.retval
= -HUGE_VAL
;
443 if (_LIB_VERSION
== _POSIX_
)
445 else if (!matherr(&exc
)) {
446 if (_LIB_VERSION
== _SVID_
) {
447 (void) WRITE2("log10: DOMAIN error\n", 20);
456 /* error only if _LIB_VERSION == _SVID_ */
458 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
460 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
461 else if (!matherr(&exc
)) {
462 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
469 /* pow(x,y) overflow */
471 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
472 if (_LIB_VERSION
== _SVID_
) {
475 if(x
<zero
&&__rint(y
)!=y
) exc
.retval
= -HUGE
;
477 exc
.retval
= HUGE_VAL
;
479 if(x
<zero
&&__rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
481 if (_LIB_VERSION
== _POSIX_
)
483 else if (!matherr(&exc
)) {
490 /* pow(x,y) underflow */
491 exc
.type
= UNDERFLOW
;
492 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
494 if (_LIB_VERSION
== _POSIX_
)
496 else if (!matherr(&exc
)) {
505 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
506 if (_LIB_VERSION
== _SVID_
)
509 exc
.retval
= -HUGE_VAL
;
510 if (_LIB_VERSION
== _POSIX_
)
512 else if (!matherr(&exc
)) {
513 if (_LIB_VERSION
== _SVID_
) {
514 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
522 /* neg**non-integral */
524 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
525 if (_LIB_VERSION
== _SVID_
)
528 exc
.retval
= zero
/zero
; /* X/Open allow NaN */
529 if (_LIB_VERSION
== _POSIX_
)
531 else if (!matherr(&exc
)) {
532 if (_LIB_VERSION
== _SVID_
) {
533 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
541 /* sinh(finite) overflow */
543 exc
.name
= type
< 100 ? "sinh" : (type
< 200
544 ? "sinhf" : "sinhl");
545 if (_LIB_VERSION
== _SVID_
)
546 exc
.retval
= ( (x
>zero
) ? HUGE
: -HUGE
);
548 exc
.retval
= ( (x
>zero
) ? HUGE_VAL
: -HUGE_VAL
);
549 if (_LIB_VERSION
== _POSIX_
)
551 else if (!matherr(&exc
)) {
560 exc
.name
= type
< 100 ? "sqrt" : (type
< 200
561 ? "sqrtf" : "sqrtl");
562 if (_LIB_VERSION
== _SVID_
)
565 exc
.retval
= zero
/zero
;
566 if (_LIB_VERSION
== _POSIX_
)
568 else if (!matherr(&exc
)) {
569 if (_LIB_VERSION
== _SVID_
) {
570 (void) WRITE2("sqrt: DOMAIN error\n", 19);
580 exc
.name
= type
< 100 ? "fmod" : (type
< 200
581 ? "fmodf" : "fmodl");
582 if (_LIB_VERSION
== _SVID_
)
585 exc
.retval
= zero
/zero
;
586 if (_LIB_VERSION
== _POSIX_
)
588 else if (!matherr(&exc
)) {
589 if (_LIB_VERSION
== _SVID_
) {
590 (void) WRITE2("fmod: DOMAIN error\n", 20);
600 exc
.name
= type
< 100 ? "remainder" : (type
< 200
603 exc
.retval
= zero
/zero
;
604 if (_LIB_VERSION
== _POSIX_
)
606 else if (!matherr(&exc
)) {
607 if (_LIB_VERSION
== _SVID_
) {
608 (void) WRITE2("remainder: DOMAIN error\n", 24);
618 exc
.name
= type
< 100 ? "acosh" : (type
< 200
619 ? "acoshf" : "acoshl");
620 exc
.retval
= zero
/zero
;
621 if (_LIB_VERSION
== _POSIX_
)
623 else if (!matherr(&exc
)) {
624 if (_LIB_VERSION
== _SVID_
) {
625 (void) WRITE2("acosh: DOMAIN error\n", 20);
635 exc
.name
= type
< 100 ? "atanh" : (type
< 200
636 ? "atanhf" : "atanhl");
637 exc
.retval
= zero
/zero
;
638 if (_LIB_VERSION
== _POSIX_
)
640 else if (!matherr(&exc
)) {
641 if (_LIB_VERSION
== _SVID_
) {
642 (void) WRITE2("atanh: DOMAIN error\n", 20);
652 exc
.name
= type
< 100 ? "atanh" : (type
< 200
653 ? "atanhf" : "atanhl");
654 exc
.retval
= x
/zero
; /* sign(x)*inf */
655 if (_LIB_VERSION
== _POSIX_
)
657 else if (!matherr(&exc
)) {
658 if (_LIB_VERSION
== _SVID_
) {
659 (void) WRITE2("atanh: SING error\n", 18);
667 /* scalb overflow; SVID also returns +-HUGE_VAL */
669 exc
.name
= type
< 100 ? "scalb" : (type
< 200
670 ? "scalbf" : "scalbl");
671 exc
.retval
= x
> zero
? HUGE_VAL
: -HUGE_VAL
;
672 if (_LIB_VERSION
== _POSIX_
)
674 else if (!matherr(&exc
)) {
681 /* scalb underflow */
682 exc
.type
= UNDERFLOW
;
683 exc
.name
= type
< 100 ? "scalb" : (type
< 200
684 ? "scalbf" : "scalbl");
685 exc
.retval
= __copysign(zero
,x
);
686 if (_LIB_VERSION
== _POSIX_
)
688 else if (!matherr(&exc
)) {
695 /* j0(|x|>X_TLOSS) */
697 exc
.name
= type
< 100 ? "j0" : (type
< 200 ? "j0f" : "j0l");
699 if (_LIB_VERSION
== _POSIX_
)
701 else if (!matherr(&exc
)) {
702 if (_LIB_VERSION
== _SVID_
) {
703 (void) WRITE2(exc
.name
, 2);
704 (void) WRITE2(": TLOSS error\n", 14);
714 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
716 if (_LIB_VERSION
== _POSIX_
)
718 else if (!matherr(&exc
)) {
719 if (_LIB_VERSION
== _SVID_
) {
720 (void) WRITE2(exc
.name
, 2);
721 (void) WRITE2(": TLOSS error\n", 14);
729 /* j1(|x|>X_TLOSS) */
731 exc
.name
= type
< 100 ? "j1" : (type
< 200 ? "j1f" : "j1l");
733 if (_LIB_VERSION
== _POSIX_
)
735 else if (!matherr(&exc
)) {
736 if (_LIB_VERSION
== _SVID_
) {
737 (void) WRITE2(exc
.name
, 2);
738 (void) WRITE2(": TLOSS error\n", 14);
748 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
750 if (_LIB_VERSION
== _POSIX_
)
752 else if (!matherr(&exc
)) {
753 if (_LIB_VERSION
== _SVID_
) {
754 (void) WRITE2(exc
.name
, 2);
755 (void) WRITE2(": TLOSS error\n", 14);
763 /* jn(|x|>X_TLOSS) */
765 exc
.name
= type
< 100 ? "jn" : (type
< 200 ? "jnf" : "jnl");
767 if (_LIB_VERSION
== _POSIX_
)
769 else if (!matherr(&exc
)) {
770 if (_LIB_VERSION
== _SVID_
) {
771 (void) WRITE2(exc
.name
, 2);
772 (void) WRITE2(": TLOSS error\n", 14);
782 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
784 if (_LIB_VERSION
== _POSIX_
)
786 else if (!matherr(&exc
)) {
787 if (_LIB_VERSION
== _SVID_
) {
788 (void) WRITE2(exc
.name
, 2);
789 (void) WRITE2(": TLOSS error\n", 14);
797 /* gamma(finite) overflow */
799 exc
.name
= type
< 100 ? "gamma" : (type
< 200
800 ? "gammaf" : "gammal");
801 if (_LIB_VERSION
== _SVID_
)
804 exc
.retval
= HUGE_VAL
;
805 if (_LIB_VERSION
== _POSIX_
)
807 else if (!matherr(&exc
)) {
814 /* gamma(-integer) or gamma(0) */
816 exc
.name
= type
< 100 ? "gamma" : (type
< 200
817 ? "gammaf" : "gammal");
818 if (_LIB_VERSION
== _SVID_
)
821 exc
.retval
= HUGE_VAL
;
822 if (_LIB_VERSION
== _POSIX_
)
824 else if (!matherr(&exc
)) {
825 if (_LIB_VERSION
== _SVID_
) {
826 (void) WRITE2("gamma: SING error\n", 18);
835 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
837 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
839 if (_LIB_VERSION
== _IEEE_
||
840 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
841 else if (!matherr(&exc
)) {