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"
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)
31 #endif /* !defined(_USE_WRITE) */
34 static const double zero
= 0.0; /* used as const */
36 static double zero
= 0.0; /* used as const */
40 * Standard conformance (non-IEEE) on exception cases.
55 * 14-- lgamma(finite) overflow
56 * 15-- lgamma(-integer)
62 * 21-- pow(x,y) overflow
63 * 22-- pow(x,y) underflow
64 * 23-- pow(0,negative)
65 * 24-- pow(neg,non-integral)
66 * 25-- sinh(finite) overflow
74 * 33-- scalb underflow
75 * 34-- j0(|x|>X_TLOSS)
77 * 36-- j1(|x|>X_TLOSS)
79 * 38-- jn(|x|>X_TLOSS, n)
80 * 39-- yn(x>X_TLOSS, n)
81 * 40-- gamma(finite) overflow
82 * 41-- gamma(-integer)
88 double __kernel_standard(double x
, double y
, int type
)
90 double __kernel_standard(x
,y
,type
)
95 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
99 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
103 (void) fflush(stdout
);
112 exc
.name
= type
< 100 ? "acos" : "acosf";
114 if (_LIB_VERSION
== _POSIX_
)
116 else if (!matherr(&exc
)) {
117 if(_LIB_VERSION
== _SVID_
) {
118 (void) WRITE2("acos: DOMAIN error\n", 19);
127 exc
.name
= type
< 100 ? "asin" : "asinf";
129 if(_LIB_VERSION
== _POSIX_
)
131 else if (!matherr(&exc
)) {
132 if(_LIB_VERSION
== _SVID_
) {
133 (void) WRITE2("asin: DOMAIN error\n", 19);
144 exc
.name
= type
< 100 ? "atan2" : "atan2f";
146 if(_LIB_VERSION
== _POSIX_
)
148 else if (!matherr(&exc
)) {
149 if(_LIB_VERSION
== _SVID_
) {
150 (void) WRITE2("atan2: DOMAIN error\n", 20);
157 /* hypot(finite,finite) overflow */
159 exc
.name
= type
< 100 ? "hypot" : "hypotf";
160 if (_LIB_VERSION
== _SVID_
)
163 exc
.retval
= HUGE_VAL
;
164 if (_LIB_VERSION
== _POSIX_
)
166 else if (!matherr(&exc
)) {
172 /* cosh(finite) overflow */
174 exc
.name
= type
< 100 ? "cosh" : "coshf";
175 if (_LIB_VERSION
== _SVID_
)
178 exc
.retval
= HUGE_VAL
;
179 if (_LIB_VERSION
== _POSIX_
)
181 else if (!matherr(&exc
)) {
187 /* exp(finite) overflow */
189 exc
.name
= type
< 100 ? "exp" : "expf";
190 if (_LIB_VERSION
== _SVID_
)
193 exc
.retval
= HUGE_VAL
;
194 if (_LIB_VERSION
== _POSIX_
)
196 else if (!matherr(&exc
)) {
202 /* exp(finite) underflow */
203 exc
.type
= UNDERFLOW
;
204 exc
.name
= type
< 100 ? "exp" : "expf";
206 if (_LIB_VERSION
== _POSIX_
)
208 else if (!matherr(&exc
)) {
215 exc
.type
= DOMAIN
; /* should be SING for IEEE */
216 exc
.name
= type
< 100 ? "y0" : "y0f";
217 if (_LIB_VERSION
== _SVID_
)
220 exc
.retval
= -HUGE_VAL
;
221 if (_LIB_VERSION
== _POSIX_
)
223 else if (!matherr(&exc
)) {
224 if (_LIB_VERSION
== _SVID_
) {
225 (void) WRITE2("y0: DOMAIN error\n", 17);
234 exc
.name
= type
< 100 ? "y0" : "y0f";
235 if (_LIB_VERSION
== _SVID_
)
238 exc
.retval
= -HUGE_VAL
;
239 if (_LIB_VERSION
== _POSIX_
)
241 else if (!matherr(&exc
)) {
242 if (_LIB_VERSION
== _SVID_
) {
243 (void) WRITE2("y0: DOMAIN error\n", 17);
251 exc
.type
= DOMAIN
; /* should be SING for IEEE */
252 exc
.name
= type
< 100 ? "y1" : "y1f";
253 if (_LIB_VERSION
== _SVID_
)
256 exc
.retval
= -HUGE_VAL
;
257 if (_LIB_VERSION
== _POSIX_
)
259 else if (!matherr(&exc
)) {
260 if (_LIB_VERSION
== _SVID_
) {
261 (void) WRITE2("y1: DOMAIN error\n", 17);
270 exc
.name
= type
< 100 ? "y1" : "y1f";
271 if (_LIB_VERSION
== _SVID_
)
274 exc
.retval
= -HUGE_VAL
;
275 if (_LIB_VERSION
== _POSIX_
)
277 else if (!matherr(&exc
)) {
278 if (_LIB_VERSION
== _SVID_
) {
279 (void) WRITE2("y1: DOMAIN error\n", 17);
287 exc
.type
= DOMAIN
; /* should be SING for IEEE */
288 exc
.name
= type
< 100 ? "yn" : "ynf";
289 if (_LIB_VERSION
== _SVID_
)
292 exc
.retval
= -HUGE_VAL
;
293 if (_LIB_VERSION
== _POSIX_
)
295 else if (!matherr(&exc
)) {
296 if (_LIB_VERSION
== _SVID_
) {
297 (void) WRITE2("yn: DOMAIN error\n", 17);
306 exc
.name
= type
< 100 ? "yn" : "ynf";
307 if (_LIB_VERSION
== _SVID_
)
310 exc
.retval
= -HUGE_VAL
;
311 if (_LIB_VERSION
== _POSIX_
)
313 else if (!matherr(&exc
)) {
314 if (_LIB_VERSION
== _SVID_
) {
315 (void) WRITE2("yn: DOMAIN error\n", 17);
322 /* lgamma(finite) overflow */
324 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
325 if (_LIB_VERSION
== _SVID_
)
328 exc
.retval
= HUGE_VAL
;
329 if (_LIB_VERSION
== _POSIX_
)
331 else if (!matherr(&exc
)) {
337 /* lgamma(-integer) or lgamma(0) */
339 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
340 if (_LIB_VERSION
== _SVID_
)
343 exc
.retval
= HUGE_VAL
;
344 if (_LIB_VERSION
== _POSIX_
)
346 else if (!matherr(&exc
)) {
347 if (_LIB_VERSION
== _SVID_
) {
348 (void) WRITE2("lgamma: SING error\n", 19);
357 exc
.name
= type
< 100 ? "log" : "logf";
358 if (_LIB_VERSION
== _SVID_
)
361 exc
.retval
= -HUGE_VAL
;
362 if (_LIB_VERSION
== _POSIX_
)
364 else if (!matherr(&exc
)) {
365 if (_LIB_VERSION
== _SVID_
) {
366 (void) WRITE2("log: SING error\n", 16);
375 exc
.name
= type
< 100 ? "log" : "logf";
376 if (_LIB_VERSION
== _SVID_
)
379 exc
.retval
= -HUGE_VAL
;
380 if (_LIB_VERSION
== _POSIX_
)
382 else if (!matherr(&exc
)) {
383 if (_LIB_VERSION
== _SVID_
) {
384 (void) WRITE2("log: DOMAIN error\n", 18);
393 exc
.name
= type
< 100 ? "log10" : "log10f";
394 if (_LIB_VERSION
== _SVID_
)
397 exc
.retval
= -HUGE_VAL
;
398 if (_LIB_VERSION
== _POSIX_
)
400 else if (!matherr(&exc
)) {
401 if (_LIB_VERSION
== _SVID_
) {
402 (void) WRITE2("log10: SING error\n", 18);
411 exc
.name
= type
< 100 ? "log10" : "log10f";
412 if (_LIB_VERSION
== _SVID_
)
415 exc
.retval
= -HUGE_VAL
;
416 if (_LIB_VERSION
== _POSIX_
)
418 else if (!matherr(&exc
)) {
419 if (_LIB_VERSION
== _SVID_
) {
420 (void) WRITE2("log10: DOMAIN error\n", 20);
428 /* error only if _LIB_VERSION == _SVID_ */
430 exc
.name
= type
< 100 ? "pow" : "powf";
432 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
433 else if (!matherr(&exc
)) {
434 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
440 /* pow(x,y) overflow */
442 exc
.name
= type
< 100 ? "pow" : "powf";
443 if (_LIB_VERSION
== _SVID_
) {
446 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE
;
448 exc
.retval
= HUGE_VAL
;
450 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
452 if (_LIB_VERSION
== _POSIX_
)
454 else if (!matherr(&exc
)) {
460 /* pow(x,y) underflow */
461 exc
.type
= UNDERFLOW
;
462 exc
.name
= type
< 100 ? "pow" : "powf";
464 if (_LIB_VERSION
== _POSIX_
)
466 else if (!matherr(&exc
)) {
474 exc
.name
= type
< 100 ? "pow" : "powf";
475 if (_LIB_VERSION
== _SVID_
)
478 exc
.retval
= -HUGE_VAL
;
479 if (_LIB_VERSION
== _POSIX_
)
481 else if (!matherr(&exc
)) {
482 if (_LIB_VERSION
== _SVID_
) {
483 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
490 /* neg**non-integral */
492 exc
.name
= type
< 100 ? "pow" : "powf";
493 if (_LIB_VERSION
== _SVID_
)
496 exc
.retval
= zero
/zero
; /* X/Open allow NaN */
497 if (_LIB_VERSION
== _POSIX_
)
499 else if (!matherr(&exc
)) {
500 if (_LIB_VERSION
== _SVID_
) {
501 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
508 /* sinh(finite) overflow */
510 exc
.name
= type
< 100 ? "sinh" : "sinhf";
511 if (_LIB_VERSION
== _SVID_
)
512 exc
.retval
= ( (x
>zero
) ? HUGE
: -HUGE
);
514 exc
.retval
= ( (x
>zero
) ? HUGE_VAL
: -HUGE_VAL
);
515 if (_LIB_VERSION
== _POSIX_
)
517 else if (!matherr(&exc
)) {
525 exc
.name
= type
< 100 ? "sqrt" : "sqrtf";
526 if (_LIB_VERSION
== _SVID_
)
529 exc
.retval
= zero
/zero
;
530 if (_LIB_VERSION
== _POSIX_
)
532 else if (!matherr(&exc
)) {
533 if (_LIB_VERSION
== _SVID_
) {
534 (void) WRITE2("sqrt: DOMAIN error\n", 19);
543 exc
.name
= type
< 100 ? "fmod" : "fmodf";
544 if (_LIB_VERSION
== _SVID_
)
547 exc
.retval
= zero
/zero
;
548 if (_LIB_VERSION
== _POSIX_
)
550 else if (!matherr(&exc
)) {
551 if (_LIB_VERSION
== _SVID_
) {
552 (void) WRITE2("fmod: DOMAIN error\n", 20);
561 exc
.name
= type
< 100 ? "remainder" : "remainderf";
562 exc
.retval
= zero
/zero
;
563 if (_LIB_VERSION
== _POSIX_
)
565 else if (!matherr(&exc
)) {
566 if (_LIB_VERSION
== _SVID_
) {
567 (void) WRITE2("remainder: DOMAIN error\n", 24);
576 exc
.name
= type
< 100 ? "acosh" : "acoshf";
577 exc
.retval
= zero
/zero
;
578 if (_LIB_VERSION
== _POSIX_
)
580 else if (!matherr(&exc
)) {
581 if (_LIB_VERSION
== _SVID_
) {
582 (void) WRITE2("acosh: DOMAIN error\n", 20);
591 exc
.name
= type
< 100 ? "atanh" : "atanhf";
592 exc
.retval
= zero
/zero
;
593 if (_LIB_VERSION
== _POSIX_
)
595 else if (!matherr(&exc
)) {
596 if (_LIB_VERSION
== _SVID_
) {
597 (void) WRITE2("atanh: DOMAIN error\n", 20);
606 exc
.name
= type
< 100 ? "atanh" : "atanhf";
607 exc
.retval
= x
/zero
; /* sign(x)*inf */
608 if (_LIB_VERSION
== _POSIX_
)
610 else if (!matherr(&exc
)) {
611 if (_LIB_VERSION
== _SVID_
) {
612 (void) WRITE2("atanh: SING error\n", 18);
619 /* scalb overflow; SVID also returns +-HUGE_VAL */
621 exc
.name
= type
< 100 ? "scalb" : "scalbf";
622 exc
.retval
= x
> zero
? HUGE_VAL
: -HUGE_VAL
;
623 if (_LIB_VERSION
== _POSIX_
)
625 else if (!matherr(&exc
)) {
631 /* scalb underflow */
632 exc
.type
= UNDERFLOW
;
633 exc
.name
= type
< 100 ? "scalb" : "scalbf";
634 exc
.retval
= copysign(zero
,x
);
635 if (_LIB_VERSION
== _POSIX_
)
637 else if (!matherr(&exc
)) {
643 /* j0(|x|>X_TLOSS) */
645 exc
.name
= type
< 100 ? "j0" : "j0f";
647 if (_LIB_VERSION
== _POSIX_
)
649 else if (!matherr(&exc
)) {
650 if (_LIB_VERSION
== _SVID_
) {
651 (void) WRITE2(exc
.name
, 2);
652 (void) WRITE2(": TLOSS error\n", 14);
661 exc
.name
= type
< 100 ? "y0" : "y0f";
663 if (_LIB_VERSION
== _POSIX_
)
665 else if (!matherr(&exc
)) {
666 if (_LIB_VERSION
== _SVID_
) {
667 (void) WRITE2(exc
.name
, 2);
668 (void) WRITE2(": TLOSS error\n", 14);
675 /* j1(|x|>X_TLOSS) */
677 exc
.name
= type
< 100 ? "j1" : "j1f";
679 if (_LIB_VERSION
== _POSIX_
)
681 else if (!matherr(&exc
)) {
682 if (_LIB_VERSION
== _SVID_
) {
683 (void) WRITE2(exc
.name
, 2);
684 (void) WRITE2(": TLOSS error\n", 14);
693 exc
.name
= type
< 100 ? "y1" : "y1f";
695 if (_LIB_VERSION
== _POSIX_
)
697 else if (!matherr(&exc
)) {
698 if (_LIB_VERSION
== _SVID_
) {
699 (void) WRITE2(exc
.name
, 2);
700 (void) WRITE2(": TLOSS error\n", 14);
707 /* jn(|x|>X_TLOSS) */
709 exc
.name
= type
< 100 ? "jn" : "jnf";
711 if (_LIB_VERSION
== _POSIX_
)
713 else if (!matherr(&exc
)) {
714 if (_LIB_VERSION
== _SVID_
) {
715 (void) WRITE2(exc
.name
, 2);
716 (void) WRITE2(": TLOSS error\n", 14);
725 exc
.name
= type
< 100 ? "yn" : "ynf";
727 if (_LIB_VERSION
== _POSIX_
)
729 else if (!matherr(&exc
)) {
730 if (_LIB_VERSION
== _SVID_
) {
731 (void) WRITE2(exc
.name
, 2);
732 (void) WRITE2(": TLOSS error\n", 14);
739 /* gamma(finite) overflow */
741 exc
.name
= type
< 100 ? "gamma" : "gammaf";
742 if (_LIB_VERSION
== _SVID_
)
745 exc
.retval
= HUGE_VAL
;
746 if (_LIB_VERSION
== _POSIX_
)
748 else if (!matherr(&exc
)) {
754 /* gamma(-integer) or gamma(0) */
756 exc
.name
= type
< 100 ? "gamma" : "gammaf";
757 if (_LIB_VERSION
== _SVID_
)
760 exc
.retval
= HUGE_VAL
;
761 if (_LIB_VERSION
== _POSIX_
)
763 else if (!matherr(&exc
)) {
764 if (_LIB_VERSION
== _SVID_
) {
765 (void) WRITE2("gamma: SING error\n", 18);
773 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
775 exc
.name
= type
< 100 ? "pow" : "powf";
777 if (_LIB_VERSION
== _IEEE_
||
778 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
779 else if (!matherr(&exc
)) {
786 #endif /* _IEEE_LIBM */