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"
24 #include <stdio.h> /* fputs(), stderr */
25 #define WRITE2(u,v) fputs(u, stderr)
26 #else /* !defined(_USE_WRITE) */
27 #include <unistd.h> /* write */
28 #define WRITE2(u,v) write(2, u, v)
30 #endif /* !defined(_USE_WRITE) */
33 static const double zero
= 0.0; /* used as const */
35 static double zero
= 0.0; /* used as const */
39 * Standard conformance (non-IEEE) on exception cases.
54 * 14-- lgamma(finite) overflow
55 * 15-- lgamma(-integer)
61 * 21-- pow(x,y) overflow
62 * 22-- pow(x,y) underflow
63 * 23-- pow(0,negative)
64 * 24-- pow(neg,non-integral)
65 * 25-- sinh(finite) overflow
73 * 33-- scalb underflow
74 * 34-- j0(|x|>X_TLOSS)
76 * 36-- j1(|x|>X_TLOSS)
78 * 38-- jn(|x|>X_TLOSS, n)
79 * 39-- yn(x>X_TLOSS, n)
80 * 40-- gamma(finite) overflow
81 * 41-- gamma(-integer)
87 double __kernel_standard(double x
, double y
, int type
)
89 double __kernel_standard(x
,y
,type
)
94 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
98 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
102 (void) fflush(stdout
);
112 exc
.name
= type
< 100 ? "acos" : (type
< 200
113 ? "acosf" : "acosl");;
114 if (_LIB_VERSION
== _SVID_
)
118 if (_LIB_VERSION
== _POSIX_
)
120 else if (!matherr(&exc
)) {
121 if(_LIB_VERSION
== _SVID_
) {
122 (void) WRITE2("acos: DOMAIN error\n", 19);
132 exc
.name
= type
< 100 ? "asin" : (type
< 200
133 ? "asinf" : "asinl");
134 if (_LIB_VERSION
== _SVID_
)
138 if(_LIB_VERSION
== _POSIX_
)
140 else if (!matherr(&exc
)) {
141 if(_LIB_VERSION
== _SVID_
) {
142 (void) WRITE2("asin: DOMAIN error\n", 19);
154 exc
.name
= type
< 100 ? "atan2" : (type
< 200
155 ? "atan2f" : "atan2l");
156 assert (_LIB_VERSION
== _SVID_
);
158 if(_LIB_VERSION
== _POSIX_
)
160 else if (!matherr(&exc
)) {
161 if(_LIB_VERSION
== _SVID_
) {
162 (void) WRITE2("atan2: DOMAIN error\n", 20);
170 /* hypot(finite,finite) overflow */
172 exc
.name
= type
< 100 ? "hypot" : (type
< 200
173 ? "hypotf" : "hypotl");
174 if (_LIB_VERSION
== _SVID_
)
177 exc
.retval
= HUGE_VAL
;
178 if (_LIB_VERSION
== _POSIX_
)
179 __set_errno (ERANGE
);
180 else if (!matherr(&exc
)) {
181 __set_errno (ERANGE
);
187 /* cosh(finite) overflow */
189 exc
.name
= type
< 100 ? "cosh" : (type
< 200
190 ? "coshf" : "coshl");
191 if (_LIB_VERSION
== _SVID_
)
194 exc
.retval
= HUGE_VAL
;
195 if (_LIB_VERSION
== _POSIX_
)
196 __set_errno (ERANGE
);
197 else if (!matherr(&exc
)) {
198 __set_errno (ERANGE
);
204 /* exp(finite) overflow */
206 exc
.name
= type
< 100 ? "exp" : (type
< 200
208 if (_LIB_VERSION
== _SVID_
)
211 exc
.retval
= HUGE_VAL
;
212 if (_LIB_VERSION
== _POSIX_
)
213 __set_errno (ERANGE
);
214 else if (!matherr(&exc
)) {
215 __set_errno (ERANGE
);
221 /* exp(finite) underflow */
222 exc
.type
= UNDERFLOW
;
223 exc
.name
= type
< 100 ? "exp" : (type
< 200
226 if (_LIB_VERSION
== _POSIX_
)
227 __set_errno (ERANGE
);
228 else if (!matherr(&exc
)) {
229 __set_errno (ERANGE
);
236 exc
.type
= DOMAIN
; /* should be SING for IEEE */
237 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
238 if (_LIB_VERSION
== _SVID_
)
241 exc
.retval
= -HUGE_VAL
;
242 if (_LIB_VERSION
== _POSIX_
)
244 else if (!matherr(&exc
)) {
245 if (_LIB_VERSION
== _SVID_
) {
246 (void) WRITE2("y0: DOMAIN error\n", 17);
256 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
257 if (_LIB_VERSION
== _SVID_
)
260 exc
.retval
= -HUGE_VAL
;
261 if (_LIB_VERSION
== _POSIX_
)
263 else if (!matherr(&exc
)) {
264 if (_LIB_VERSION
== _SVID_
) {
265 (void) WRITE2("y0: DOMAIN error\n", 17);
274 exc
.type
= DOMAIN
; /* should be SING for IEEE */
275 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
276 if (_LIB_VERSION
== _SVID_
)
279 exc
.retval
= -HUGE_VAL
;
280 if (_LIB_VERSION
== _POSIX_
)
282 else if (!matherr(&exc
)) {
283 if (_LIB_VERSION
== _SVID_
) {
284 (void) WRITE2("y1: DOMAIN error\n", 17);
294 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
295 if (_LIB_VERSION
== _SVID_
)
298 exc
.retval
= -HUGE_VAL
;
299 if (_LIB_VERSION
== _POSIX_
)
301 else if (!matherr(&exc
)) {
302 if (_LIB_VERSION
== _SVID_
) {
303 (void) WRITE2("y1: DOMAIN error\n", 17);
312 exc
.type
= DOMAIN
; /* should be SING for IEEE */
313 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
314 if (_LIB_VERSION
== _SVID_
)
317 exc
.retval
= -HUGE_VAL
;
318 if (_LIB_VERSION
== _POSIX_
)
320 else if (!matherr(&exc
)) {
321 if (_LIB_VERSION
== _SVID_
) {
322 (void) WRITE2("yn: DOMAIN error\n", 17);
332 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
333 if (_LIB_VERSION
== _SVID_
)
336 exc
.retval
= -HUGE_VAL
;
337 if (_LIB_VERSION
== _POSIX_
)
339 else if (!matherr(&exc
)) {
340 if (_LIB_VERSION
== _SVID_
) {
341 (void) WRITE2("yn: DOMAIN error\n", 17);
349 /* lgamma(finite) overflow */
351 exc
.name
= type
< 100 ? "lgamma" : (type
< 200
352 ? "lgammaf" : "lgammal");
353 if (_LIB_VERSION
== _SVID_
)
356 exc
.retval
= HUGE_VAL
;
357 if (_LIB_VERSION
== _POSIX_
)
358 __set_errno (ERANGE
);
359 else if (!matherr(&exc
)) {
360 __set_errno (ERANGE
);
366 /* lgamma(-integer) or lgamma(0) */
368 exc
.name
= type
< 100 ? "lgamma" : (type
< 200
369 ? "lgammaf" : "lgammal");
370 if (_LIB_VERSION
== _SVID_
)
373 exc
.retval
= HUGE_VAL
;
374 if (_LIB_VERSION
== _POSIX_
)
376 else if (!matherr(&exc
)) {
377 if (_LIB_VERSION
== _SVID_
) {
378 (void) WRITE2("lgamma: SING error\n", 19);
388 exc
.name
= type
< 100 ? "log" : (type
< 200 ? "logf" : "logl");
389 if (_LIB_VERSION
== _SVID_
)
392 exc
.retval
= -HUGE_VAL
;
393 if (_LIB_VERSION
== _POSIX_
)
394 __set_errno (ERANGE
);
395 else if (!matherr(&exc
)) {
396 if (_LIB_VERSION
== _SVID_
) {
397 (void) WRITE2("log: SING error\n", 16);
407 exc
.name
= type
< 100 ? "log" : (type
< 200 ? "logf" : "logl");
408 if (_LIB_VERSION
== _SVID_
)
412 if (_LIB_VERSION
== _POSIX_
)
414 else if (!matherr(&exc
)) {
415 if (_LIB_VERSION
== _SVID_
) {
416 (void) WRITE2("log: DOMAIN error\n", 18);
426 exc
.name
= type
< 100 ? "log10" : (type
< 200
427 ? "log10f" : "log10l");
428 if (_LIB_VERSION
== _SVID_
)
431 exc
.retval
= -HUGE_VAL
;
432 if (_LIB_VERSION
== _POSIX_
)
433 __set_errno (ERANGE
);
434 else if (!matherr(&exc
)) {
435 if (_LIB_VERSION
== _SVID_
) {
436 (void) WRITE2("log10: SING error\n", 18);
446 exc
.name
= type
< 100 ? "log10" : (type
< 200
447 ? "log10f" : "log10l");
448 if (_LIB_VERSION
== _SVID_
)
452 if (_LIB_VERSION
== _POSIX_
)
454 else if (!matherr(&exc
)) {
455 if (_LIB_VERSION
== _SVID_
) {
456 (void) WRITE2("log10: DOMAIN error\n", 20);
465 /* error only if _LIB_VERSION == _SVID_ */
467 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
469 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
470 else if (!matherr(&exc
)) {
471 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
478 /* pow(x,y) overflow */
480 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
481 if (_LIB_VERSION
== _SVID_
) {
484 if(x
<zero
&&__rint(y
)!=y
) exc
.retval
= -HUGE
;
486 exc
.retval
= HUGE_VAL
;
488 if(x
<zero
&&__rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
490 if (_LIB_VERSION
== _POSIX_
)
491 __set_errno (ERANGE
);
492 else if (!matherr(&exc
)) {
493 __set_errno (ERANGE
);
499 /* pow(x,y) underflow */
500 exc
.type
= UNDERFLOW
;
501 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
503 if (_LIB_VERSION
== _POSIX_
)
504 __set_errno (ERANGE
);
505 else if (!matherr(&exc
)) {
506 __set_errno (ERANGE
);
514 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
515 if (_LIB_VERSION
== _SVID_
)
518 exc
.retval
= -HUGE_VAL
;
519 if (_LIB_VERSION
== _POSIX_
)
521 else if (!matherr(&exc
)) {
522 if (_LIB_VERSION
== _SVID_
) {
523 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
533 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
534 if (_LIB_VERSION
== _SVID_
)
537 exc
.retval
= HUGE_VAL
;
538 if (_LIB_VERSION
== _POSIX_
)
540 else if (!matherr(&exc
)) {
541 if (_LIB_VERSION
== _SVID_
) {
542 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
550 /* neg**non-integral */
552 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
553 if (_LIB_VERSION
== _SVID_
)
556 exc
.retval
= zero
/zero
; /* X/Open allow NaN */
557 if (_LIB_VERSION
== _POSIX_
)
559 else if (!matherr(&exc
)) {
560 if (_LIB_VERSION
== _SVID_
) {
561 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
569 /* sinh(finite) overflow */
571 exc
.name
= type
< 100 ? "sinh" : (type
< 200
572 ? "sinhf" : "sinhl");
573 if (_LIB_VERSION
== _SVID_
)
574 exc
.retval
= ( (x
>zero
) ? HUGE
: -HUGE
);
576 exc
.retval
= ( (x
>zero
) ? HUGE_VAL
: -HUGE_VAL
);
577 if (_LIB_VERSION
== _POSIX_
)
578 __set_errno (ERANGE
);
579 else if (!matherr(&exc
)) {
580 __set_errno (ERANGE
);
588 exc
.name
= type
< 100 ? "sqrt" : (type
< 200
589 ? "sqrtf" : "sqrtl");
590 if (_LIB_VERSION
== _SVID_
)
593 exc
.retval
= zero
/zero
;
594 if (_LIB_VERSION
== _POSIX_
)
596 else if (!matherr(&exc
)) {
597 if (_LIB_VERSION
== _SVID_
) {
598 (void) WRITE2("sqrt: DOMAIN error\n", 19);
608 exc
.name
= type
< 100 ? "fmod" : (type
< 200
609 ? "fmodf" : "fmodl");
610 if (_LIB_VERSION
== _SVID_
)
613 exc
.retval
= zero
/zero
;
614 if (_LIB_VERSION
== _POSIX_
)
616 else if (!matherr(&exc
)) {
617 if (_LIB_VERSION
== _SVID_
) {
618 (void) WRITE2("fmod: DOMAIN error\n", 20);
628 exc
.name
= type
< 100 ? "remainder" : (type
< 200
631 exc
.retval
= zero
/zero
;
632 if (_LIB_VERSION
== _POSIX_
)
634 else if (!matherr(&exc
)) {
635 if (_LIB_VERSION
== _SVID_
) {
636 (void) WRITE2("remainder: DOMAIN error\n", 24);
646 exc
.name
= type
< 100 ? "acosh" : (type
< 200
647 ? "acoshf" : "acoshl");
648 exc
.retval
= zero
/zero
;
649 if (_LIB_VERSION
== _POSIX_
)
651 else if (!matherr(&exc
)) {
652 if (_LIB_VERSION
== _SVID_
) {
653 (void) WRITE2("acosh: DOMAIN error\n", 20);
663 exc
.name
= type
< 100 ? "atanh" : (type
< 200
664 ? "atanhf" : "atanhl");
665 exc
.retval
= zero
/zero
;
666 if (_LIB_VERSION
== _POSIX_
)
668 else if (!matherr(&exc
)) {
669 if (_LIB_VERSION
== _SVID_
) {
670 (void) WRITE2("atanh: DOMAIN error\n", 20);
680 exc
.name
= type
< 100 ? "atanh" : (type
< 200
681 ? "atanhf" : "atanhl");
682 exc
.retval
= x
/zero
; /* sign(x)*inf */
683 if (_LIB_VERSION
== _POSIX_
)
685 else if (!matherr(&exc
)) {
686 if (_LIB_VERSION
== _SVID_
) {
687 (void) WRITE2("atanh: SING error\n", 18);
695 /* scalb overflow; SVID also returns +-HUGE_VAL */
697 exc
.name
= type
< 100 ? "scalb" : (type
< 200
698 ? "scalbf" : "scalbl");
699 exc
.retval
= x
> zero
? HUGE_VAL
: -HUGE_VAL
;
700 if (_LIB_VERSION
== _POSIX_
)
701 __set_errno (ERANGE
);
702 else if (!matherr(&exc
)) {
703 __set_errno (ERANGE
);
709 /* scalb underflow */
710 exc
.type
= UNDERFLOW
;
711 exc
.name
= type
< 100 ? "scalb" : (type
< 200
712 ? "scalbf" : "scalbl");
713 exc
.retval
= __copysign(zero
,x
);
714 if (_LIB_VERSION
== _POSIX_
)
715 __set_errno (ERANGE
);
716 else if (!matherr(&exc
)) {
717 __set_errno (ERANGE
);
723 /* j0(|x|>X_TLOSS) */
725 exc
.name
= type
< 100 ? "j0" : (type
< 200 ? "j0f" : "j0l");
727 if (_LIB_VERSION
== _POSIX_
)
728 __set_errno (ERANGE
);
729 else if (!matherr(&exc
)) {
730 if (_LIB_VERSION
== _SVID_
) {
731 (void) WRITE2(exc
.name
, 2);
732 (void) WRITE2(": TLOSS error\n", 14);
734 __set_errno (ERANGE
);
742 exc
.name
= type
< 100 ? "y0" : (type
< 200 ? "y0f" : "y0l");
744 if (_LIB_VERSION
== _POSIX_
)
745 __set_errno (ERANGE
);
746 else if (!matherr(&exc
)) {
747 if (_LIB_VERSION
== _SVID_
) {
748 (void) WRITE2(exc
.name
, 2);
749 (void) WRITE2(": TLOSS error\n", 14);
751 __set_errno (ERANGE
);
757 /* j1(|x|>X_TLOSS) */
759 exc
.name
= type
< 100 ? "j1" : (type
< 200 ? "j1f" : "j1l");
761 if (_LIB_VERSION
== _POSIX_
)
762 __set_errno (ERANGE
);
763 else if (!matherr(&exc
)) {
764 if (_LIB_VERSION
== _SVID_
) {
765 (void) WRITE2(exc
.name
, 2);
766 (void) WRITE2(": TLOSS error\n", 14);
768 __set_errno (ERANGE
);
776 exc
.name
= type
< 100 ? "y1" : (type
< 200 ? "y1f" : "y1l");
778 if (_LIB_VERSION
== _POSIX_
)
779 __set_errno (ERANGE
);
780 else if (!matherr(&exc
)) {
781 if (_LIB_VERSION
== _SVID_
) {
782 (void) WRITE2(exc
.name
, 2);
783 (void) WRITE2(": TLOSS error\n", 14);
785 __set_errno (ERANGE
);
791 /* jn(|x|>X_TLOSS) */
793 exc
.name
= type
< 100 ? "jn" : (type
< 200 ? "jnf" : "jnl");
795 if (_LIB_VERSION
== _POSIX_
)
796 __set_errno (ERANGE
);
797 else if (!matherr(&exc
)) {
798 if (_LIB_VERSION
== _SVID_
) {
799 (void) WRITE2(exc
.name
, 2);
800 (void) WRITE2(": TLOSS error\n", 14);
802 __set_errno (ERANGE
);
810 exc
.name
= type
< 100 ? "yn" : (type
< 200 ? "ynf" : "ynl");
812 if (_LIB_VERSION
== _POSIX_
)
813 __set_errno (ERANGE
);
814 else if (!matherr(&exc
)) {
815 if (_LIB_VERSION
== _SVID_
) {
816 (void) WRITE2(exc
.name
, 2);
817 (void) WRITE2(": TLOSS error\n", 14);
819 __set_errno (ERANGE
);
825 /* gamma(finite) overflow */
827 exc
.name
= type
< 100 ? "gamma" : (type
< 200
828 ? "gammaf" : "gammal");
829 if (_LIB_VERSION
== _SVID_
)
832 exc
.retval
= HUGE_VAL
;
833 if (_LIB_VERSION
== _POSIX_
)
834 __set_errno (ERANGE
);
835 else if (!matherr(&exc
)) {
836 __set_errno (ERANGE
);
842 /* gamma(-integer) or gamma(0) */
844 exc
.name
= type
< 100 ? "gamma" : (type
< 200
845 ? "gammaf" : "gammal");
846 if (_LIB_VERSION
== _SVID_
)
850 if (_LIB_VERSION
== _POSIX_
)
852 else if (!matherr(&exc
)) {
853 if (_LIB_VERSION
== _SVID_
) {
854 (void) WRITE2("gamma: SING error\n", 18);
863 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
865 exc
.name
= type
< 100 ? "pow" : (type
< 200 ? "powf" : "powl");
867 if (_LIB_VERSION
== _IEEE_
||
868 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
869 else if (!matherr(&exc
)) {
874 /* #### Last used is 43/143/243 ### */