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 * ====================================================
14 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/k_standard.c,v 1.5 1999/08/28 00:06:41 peter 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) */
30 static const double zero
= 0.0; /* used as const */
33 * Standard conformance (non-IEEE) on exception cases.
48 * 14-- lgamma(finite) overflow
49 * 15-- lgamma(-integer)
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
67 * 33-- scalb underflow
68 * 34-- j0(|x|>X_TLOSS)
70 * 36-- j1(|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)
81 __kernel_standard(double x
, double y
, int type
)
84 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
88 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
92 (void) fflush(stdout
);
101 exc
.name
= type
< 100 ? "acos" : "acosf";
103 if (_LIB_VERSION
== _POSIX_
)
105 else if (!matherr(&exc
)) {
106 if(_LIB_VERSION
== _SVID_
) {
107 (void) WRITE2("acos: DOMAIN error\n", 19);
116 exc
.name
= type
< 100 ? "asin" : "asinf";
118 if(_LIB_VERSION
== _POSIX_
)
120 else if (!matherr(&exc
)) {
121 if(_LIB_VERSION
== _SVID_
) {
122 (void) WRITE2("asin: DOMAIN error\n", 19);
133 exc
.name
= type
< 100 ? "atan2" : "atan2f";
135 if(_LIB_VERSION
== _POSIX_
)
137 else if (!matherr(&exc
)) {
138 if(_LIB_VERSION
== _SVID_
) {
139 (void) WRITE2("atan2: DOMAIN error\n", 20);
146 /* hypot(finite,finite) overflow */
148 exc
.name
= type
< 100 ? "hypot" : "hypotf";
149 if (_LIB_VERSION
== _SVID_
)
152 exc
.retval
= HUGE_VAL
;
153 if (_LIB_VERSION
== _POSIX_
)
155 else if (!matherr(&exc
)) {
161 /* cosh(finite) overflow */
163 exc
.name
= type
< 100 ? "cosh" : "coshf";
164 if (_LIB_VERSION
== _SVID_
)
167 exc
.retval
= HUGE_VAL
;
168 if (_LIB_VERSION
== _POSIX_
)
170 else if (!matherr(&exc
)) {
176 /* exp(finite) overflow */
178 exc
.name
= type
< 100 ? "exp" : "expf";
179 if (_LIB_VERSION
== _SVID_
)
182 exc
.retval
= HUGE_VAL
;
183 if (_LIB_VERSION
== _POSIX_
)
185 else if (!matherr(&exc
)) {
191 /* exp(finite) underflow */
192 exc
.type
= UNDERFLOW
;
193 exc
.name
= type
< 100 ? "exp" : "expf";
195 if (_LIB_VERSION
== _POSIX_
)
197 else if (!matherr(&exc
)) {
204 exc
.type
= DOMAIN
; /* should be SING for IEEE */
205 exc
.name
= type
< 100 ? "y0" : "y0f";
206 if (_LIB_VERSION
== _SVID_
)
209 exc
.retval
= -HUGE_VAL
;
210 if (_LIB_VERSION
== _POSIX_
)
212 else if (!matherr(&exc
)) {
213 if (_LIB_VERSION
== _SVID_
) {
214 (void) WRITE2("y0: DOMAIN error\n", 17);
223 exc
.name
= type
< 100 ? "y0" : "y0f";
224 if (_LIB_VERSION
== _SVID_
)
227 exc
.retval
= -HUGE_VAL
;
228 if (_LIB_VERSION
== _POSIX_
)
230 else if (!matherr(&exc
)) {
231 if (_LIB_VERSION
== _SVID_
) {
232 (void) WRITE2("y0: DOMAIN error\n", 17);
240 exc
.type
= DOMAIN
; /* should be SING for IEEE */
241 exc
.name
= type
< 100 ? "y1" : "y1f";
242 if (_LIB_VERSION
== _SVID_
)
245 exc
.retval
= -HUGE_VAL
;
246 if (_LIB_VERSION
== _POSIX_
)
248 else if (!matherr(&exc
)) {
249 if (_LIB_VERSION
== _SVID_
) {
250 (void) WRITE2("y1: DOMAIN error\n", 17);
259 exc
.name
= type
< 100 ? "y1" : "y1f";
260 if (_LIB_VERSION
== _SVID_
)
263 exc
.retval
= -HUGE_VAL
;
264 if (_LIB_VERSION
== _POSIX_
)
266 else if (!matherr(&exc
)) {
267 if (_LIB_VERSION
== _SVID_
) {
268 (void) WRITE2("y1: DOMAIN error\n", 17);
276 exc
.type
= DOMAIN
; /* should be SING for IEEE */
277 exc
.name
= type
< 100 ? "yn" : "ynf";
278 if (_LIB_VERSION
== _SVID_
)
281 exc
.retval
= -HUGE_VAL
;
282 if (_LIB_VERSION
== _POSIX_
)
284 else if (!matherr(&exc
)) {
285 if (_LIB_VERSION
== _SVID_
) {
286 (void) WRITE2("yn: DOMAIN error\n", 17);
295 exc
.name
= type
< 100 ? "yn" : "ynf";
296 if (_LIB_VERSION
== _SVID_
)
299 exc
.retval
= -HUGE_VAL
;
300 if (_LIB_VERSION
== _POSIX_
)
302 else if (!matherr(&exc
)) {
303 if (_LIB_VERSION
== _SVID_
) {
304 (void) WRITE2("yn: DOMAIN error\n", 17);
311 /* lgamma(finite) overflow */
313 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
314 if (_LIB_VERSION
== _SVID_
)
317 exc
.retval
= HUGE_VAL
;
318 if (_LIB_VERSION
== _POSIX_
)
320 else if (!matherr(&exc
)) {
326 /* lgamma(-integer) or lgamma(0) */
328 exc
.name
= type
< 100 ? "lgamma" : "lgammaf";
329 if (_LIB_VERSION
== _SVID_
)
332 exc
.retval
= HUGE_VAL
;
333 if (_LIB_VERSION
== _POSIX_
)
335 else if (!matherr(&exc
)) {
336 if (_LIB_VERSION
== _SVID_
) {
337 (void) WRITE2("lgamma: SING error\n", 19);
346 exc
.name
= type
< 100 ? "log" : "logf";
347 if (_LIB_VERSION
== _SVID_
)
350 exc
.retval
= -HUGE_VAL
;
351 if (_LIB_VERSION
== _POSIX_
)
353 else if (!matherr(&exc
)) {
354 if (_LIB_VERSION
== _SVID_
) {
355 (void) WRITE2("log: SING error\n", 16);
364 exc
.name
= type
< 100 ? "log" : "logf";
365 if (_LIB_VERSION
== _SVID_
)
368 exc
.retval
= -HUGE_VAL
;
369 if (_LIB_VERSION
== _POSIX_
)
371 else if (!matherr(&exc
)) {
372 if (_LIB_VERSION
== _SVID_
) {
373 (void) WRITE2("log: DOMAIN error\n", 18);
382 exc
.name
= type
< 100 ? "log10" : "log10f";
383 if (_LIB_VERSION
== _SVID_
)
386 exc
.retval
= -HUGE_VAL
;
387 if (_LIB_VERSION
== _POSIX_
)
389 else if (!matherr(&exc
)) {
390 if (_LIB_VERSION
== _SVID_
) {
391 (void) WRITE2("log10: SING error\n", 18);
400 exc
.name
= type
< 100 ? "log10" : "log10f";
401 if (_LIB_VERSION
== _SVID_
)
404 exc
.retval
= -HUGE_VAL
;
405 if (_LIB_VERSION
== _POSIX_
)
407 else if (!matherr(&exc
)) {
408 if (_LIB_VERSION
== _SVID_
) {
409 (void) WRITE2("log10: DOMAIN error\n", 20);
417 /* error only if _LIB_VERSION == _SVID_ */
419 exc
.name
= type
< 100 ? "pow" : "powf";
421 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
422 else if (!matherr(&exc
)) {
423 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
429 /* pow(x,y) overflow */
431 exc
.name
= type
< 100 ? "pow" : "powf";
432 if (_LIB_VERSION
== _SVID_
) {
435 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE
;
437 exc
.retval
= HUGE_VAL
;
439 if(x
<zero
&&rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
441 if (_LIB_VERSION
== _POSIX_
)
443 else if (!matherr(&exc
)) {
449 /* pow(x,y) underflow */
450 exc
.type
= UNDERFLOW
;
451 exc
.name
= type
< 100 ? "pow" : "powf";
453 if (_LIB_VERSION
== _POSIX_
)
455 else if (!matherr(&exc
)) {
463 exc
.name
= type
< 100 ? "pow" : "powf";
464 if (_LIB_VERSION
== _SVID_
)
467 exc
.retval
= -HUGE_VAL
;
468 if (_LIB_VERSION
== _POSIX_
)
470 else if (!matherr(&exc
)) {
471 if (_LIB_VERSION
== _SVID_
) {
472 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
479 /* neg**non-integral */
481 exc
.name
= type
< 100 ? "pow" : "powf";
482 if (_LIB_VERSION
== _SVID_
)
485 exc
.retval
= zero
/zero
; /* X/Open allow NaN */
486 if (_LIB_VERSION
== _POSIX_
)
488 else if (!matherr(&exc
)) {
489 if (_LIB_VERSION
== _SVID_
) {
490 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
497 /* sinh(finite) overflow */
499 exc
.name
= type
< 100 ? "sinh" : "sinhf";
500 if (_LIB_VERSION
== _SVID_
)
501 exc
.retval
= ( (x
>zero
) ? HUGE
: -HUGE
);
503 exc
.retval
= ( (x
>zero
) ? HUGE_VAL
: -HUGE_VAL
);
504 if (_LIB_VERSION
== _POSIX_
)
506 else if (!matherr(&exc
)) {
514 exc
.name
= type
< 100 ? "sqrt" : "sqrtf";
515 if (_LIB_VERSION
== _SVID_
)
518 exc
.retval
= zero
/zero
;
519 if (_LIB_VERSION
== _POSIX_
)
521 else if (!matherr(&exc
)) {
522 if (_LIB_VERSION
== _SVID_
) {
523 (void) WRITE2("sqrt: DOMAIN error\n", 19);
532 exc
.name
= type
< 100 ? "fmod" : "fmodf";
533 if (_LIB_VERSION
== _SVID_
)
536 exc
.retval
= zero
/zero
;
537 if (_LIB_VERSION
== _POSIX_
)
539 else if (!matherr(&exc
)) {
540 if (_LIB_VERSION
== _SVID_
) {
541 (void) WRITE2("fmod: DOMAIN error\n", 20);
550 exc
.name
= type
< 100 ? "remainder" : "remainderf";
551 exc
.retval
= zero
/zero
;
552 if (_LIB_VERSION
== _POSIX_
)
554 else if (!matherr(&exc
)) {
555 if (_LIB_VERSION
== _SVID_
) {
556 (void) WRITE2("remainder: DOMAIN error\n", 24);
565 exc
.name
= type
< 100 ? "acosh" : "acoshf";
566 exc
.retval
= zero
/zero
;
567 if (_LIB_VERSION
== _POSIX_
)
569 else if (!matherr(&exc
)) {
570 if (_LIB_VERSION
== _SVID_
) {
571 (void) WRITE2("acosh: DOMAIN error\n", 20);
580 exc
.name
= type
< 100 ? "atanh" : "atanhf";
581 exc
.retval
= zero
/zero
;
582 if (_LIB_VERSION
== _POSIX_
)
584 else if (!matherr(&exc
)) {
585 if (_LIB_VERSION
== _SVID_
) {
586 (void) WRITE2("atanh: DOMAIN error\n", 20);
595 exc
.name
= type
< 100 ? "atanh" : "atanhf";
596 exc
.retval
= x
/zero
; /* sign(x)*inf */
597 if (_LIB_VERSION
== _POSIX_
)
599 else if (!matherr(&exc
)) {
600 if (_LIB_VERSION
== _SVID_
) {
601 (void) WRITE2("atanh: SING error\n", 18);
608 /* scalb overflow; SVID also returns +-HUGE_VAL */
610 exc
.name
= type
< 100 ? "scalb" : "scalbf";
611 exc
.retval
= x
> zero
? HUGE_VAL
: -HUGE_VAL
;
612 if (_LIB_VERSION
== _POSIX_
)
614 else if (!matherr(&exc
)) {
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_
)
626 else if (!matherr(&exc
)) {
632 /* j0(|x|>X_TLOSS) */
634 exc
.name
= type
< 100 ? "j0" : "j0f";
636 if (_LIB_VERSION
== _POSIX_
)
638 else if (!matherr(&exc
)) {
639 if (_LIB_VERSION
== _SVID_
) {
640 (void) WRITE2(exc
.name
, 2);
641 (void) WRITE2(": TLOSS error\n", 14);
650 exc
.name
= type
< 100 ? "y0" : "y0f";
652 if (_LIB_VERSION
== _POSIX_
)
654 else if (!matherr(&exc
)) {
655 if (_LIB_VERSION
== _SVID_
) {
656 (void) WRITE2(exc
.name
, 2);
657 (void) WRITE2(": TLOSS error\n", 14);
664 /* j1(|x|>X_TLOSS) */
666 exc
.name
= type
< 100 ? "j1" : "j1f";
668 if (_LIB_VERSION
== _POSIX_
)
670 else if (!matherr(&exc
)) {
671 if (_LIB_VERSION
== _SVID_
) {
672 (void) WRITE2(exc
.name
, 2);
673 (void) WRITE2(": TLOSS error\n", 14);
682 exc
.name
= type
< 100 ? "y1" : "y1f";
684 if (_LIB_VERSION
== _POSIX_
)
686 else if (!matherr(&exc
)) {
687 if (_LIB_VERSION
== _SVID_
) {
688 (void) WRITE2(exc
.name
, 2);
689 (void) WRITE2(": TLOSS error\n", 14);
696 /* jn(|x|>X_TLOSS) */
698 exc
.name
= type
< 100 ? "jn" : "jnf";
700 if (_LIB_VERSION
== _POSIX_
)
702 else if (!matherr(&exc
)) {
703 if (_LIB_VERSION
== _SVID_
) {
704 (void) WRITE2(exc
.name
, 2);
705 (void) WRITE2(": TLOSS error\n", 14);
714 exc
.name
= type
< 100 ? "yn" : "ynf";
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);
728 /* gamma(finite) overflow */
730 exc
.name
= type
< 100 ? "gamma" : "gammaf";
731 if (_LIB_VERSION
== _SVID_
)
734 exc
.retval
= HUGE_VAL
;
735 if (_LIB_VERSION
== _POSIX_
)
737 else if (!matherr(&exc
)) {
743 /* gamma(-integer) or gamma(0) */
745 exc
.name
= type
< 100 ? "gamma" : "gammaf";
746 if (_LIB_VERSION
== _SVID_
)
749 exc
.retval
= HUGE_VAL
;
750 if (_LIB_VERSION
== _POSIX_
)
752 else if (!matherr(&exc
)) {
753 if (_LIB_VERSION
== _SVID_
) {
754 (void) WRITE2("gamma: SING error\n", 18);
762 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
764 exc
.name
= type
< 100 ? "pow" : "powf";
766 if (_LIB_VERSION
== _IEEE_
||
767 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
768 else if (!matherr(&exc
)) {