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);
109 exc.name = type < 100 ? "acos" : "acosf";
111 if (_LIB_VERSION == _POSIX_)
113 else if (!matherr(&exc)) {
114 if(_LIB_VERSION == _SVID_) {
115 (void) WRITE2("acos: DOMAIN error\n", 19);
124 exc.name = type < 100 ? "asin" : "asinf";
126 if(_LIB_VERSION == _POSIX_)
128 else if (!matherr(&exc)) {
129 if(_LIB_VERSION == _SVID_) {
130 (void) WRITE2("asin: DOMAIN error\n", 19);
141 exc.name = type < 100 ? "atan2" : "atan2f";
143 if(_LIB_VERSION == _POSIX_)
145 else if (!matherr(&exc)) {
146 if(_LIB_VERSION == _SVID_) {
147 (void) WRITE2("atan2: DOMAIN error\n", 20);
154 /* hypot(finite,finite) overflow */
156 exc.name = type < 100 ? "hypot" : "hypotf";
157 if (_LIB_VERSION == _SVID_)
160 exc.retval = HUGE_VAL;
161 if (_LIB_VERSION == _POSIX_)
163 else if (!matherr(&exc)) {
169 /* cosh(finite) overflow */
171 exc.name = type < 100 ? "cosh" : "coshf";
172 if (_LIB_VERSION == _SVID_)
175 exc.retval = HUGE_VAL;
176 if (_LIB_VERSION == _POSIX_)
178 else if (!matherr(&exc)) {
184 /* exp(finite) overflow */
186 exc.name = type < 100 ? "exp" : "expf";
187 if (_LIB_VERSION == _SVID_)
190 exc.retval = HUGE_VAL;
191 if (_LIB_VERSION == _POSIX_)
193 else if (!matherr(&exc)) {
199 /* exp(finite) underflow */
200 exc.type = UNDERFLOW;
201 exc.name = type < 100 ? "exp" : "expf";
203 if (_LIB_VERSION == _POSIX_)
205 else if (!matherr(&exc)) {
212 exc.type = DOMAIN; /* should be SING for IEEE */
213 exc.name = type < 100 ? "y0" : "y0f";
214 if (_LIB_VERSION == _SVID_)
217 exc.retval = -HUGE_VAL;
218 if (_LIB_VERSION == _POSIX_)
220 else if (!matherr(&exc)) {
221 if (_LIB_VERSION == _SVID_) {
222 (void) WRITE2("y0: DOMAIN error\n", 17);
231 exc.name = type < 100 ? "y0" : "y0f";
232 if (_LIB_VERSION == _SVID_)
235 exc.retval = -HUGE_VAL;
236 if (_LIB_VERSION == _POSIX_)
238 else if (!matherr(&exc)) {
239 if (_LIB_VERSION == _SVID_) {
240 (void) WRITE2("y0: DOMAIN error\n", 17);
248 exc.type = DOMAIN; /* should be SING for IEEE */
249 exc.name = type < 100 ? "y1" : "y1f";
250 if (_LIB_VERSION == _SVID_)
253 exc.retval = -HUGE_VAL;
254 if (_LIB_VERSION == _POSIX_)
256 else if (!matherr(&exc)) {
257 if (_LIB_VERSION == _SVID_) {
258 (void) WRITE2("y1: DOMAIN error\n", 17);
267 exc.name = type < 100 ? "y1" : "y1f";
268 if (_LIB_VERSION == _SVID_)
271 exc.retval = -HUGE_VAL;
272 if (_LIB_VERSION == _POSIX_)
274 else if (!matherr(&exc)) {
275 if (_LIB_VERSION == _SVID_) {
276 (void) WRITE2("y1: DOMAIN error\n", 17);
284 exc.type = DOMAIN; /* should be SING for IEEE */
285 exc.name = type < 100 ? "yn" : "ynf";
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("yn: DOMAIN error\n", 17);
303 exc.name = type < 100 ? "yn" : "ynf";
304 if (_LIB_VERSION == _SVID_)
307 exc.retval = -HUGE_VAL;
308 if (_LIB_VERSION == _POSIX_)
310 else if (!matherr(&exc)) {
311 if (_LIB_VERSION == _SVID_) {
312 (void) WRITE2("yn: DOMAIN error\n", 17);
319 /* lgamma(finite) overflow */
321 exc.name = type < 100 ? "lgamma" : "lgammaf";
322 if (_LIB_VERSION == _SVID_)
325 exc.retval = HUGE_VAL;
326 if (_LIB_VERSION == _POSIX_)
328 else if (!matherr(&exc)) {
334 /* lgamma(-integer) or lgamma(0) */
336 exc.name = type < 100 ? "lgamma" : "lgammaf";
337 if (_LIB_VERSION == _SVID_)
340 exc.retval = HUGE_VAL;
341 if (_LIB_VERSION == _POSIX_)
343 else if (!matherr(&exc)) {
344 if (_LIB_VERSION == _SVID_) {
345 (void) WRITE2("lgamma: SING error\n", 19);
354 exc.name = type < 100 ? "log" : "logf";
355 if (_LIB_VERSION == _SVID_)
358 exc.retval = -HUGE_VAL;
359 if (_LIB_VERSION == _POSIX_)
361 else if (!matherr(&exc)) {
362 if (_LIB_VERSION == _SVID_) {
363 (void) WRITE2("log: SING error\n", 16);
372 exc.name = type < 100 ? "log" : "logf";
373 if (_LIB_VERSION == _SVID_)
376 exc.retval = -HUGE_VAL;
377 if (_LIB_VERSION == _POSIX_)
379 else if (!matherr(&exc)) {
380 if (_LIB_VERSION == _SVID_) {
381 (void) WRITE2("log: DOMAIN error\n", 18);
390 exc.name = type < 100 ? "log10" : "log10f";
391 if (_LIB_VERSION == _SVID_)
394 exc.retval = -HUGE_VAL;
395 if (_LIB_VERSION == _POSIX_)
397 else if (!matherr(&exc)) {
398 if (_LIB_VERSION == _SVID_) {
399 (void) WRITE2("log10: SING error\n", 18);
408 exc.name = type < 100 ? "log10" : "log10f";
409 if (_LIB_VERSION == _SVID_)
412 exc.retval = -HUGE_VAL;
413 if (_LIB_VERSION == _POSIX_)
415 else if (!matherr(&exc)) {
416 if (_LIB_VERSION == _SVID_) {
417 (void) WRITE2("log10: DOMAIN error\n", 20);
425 /* error only if _LIB_VERSION == _SVID_ */
427 exc.name = type < 100 ? "pow" : "powf";
429 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
430 else if (!matherr(&exc)) {
431 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
437 /* pow(x,y) overflow */
439 exc.name = type < 100 ? "pow" : "powf";
440 if (_LIB_VERSION == _SVID_) {
443 if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
445 exc.retval = HUGE_VAL;
447 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
449 if (_LIB_VERSION == _POSIX_)
451 else if (!matherr(&exc)) {
457 /* pow(x,y) underflow */
458 exc.type = UNDERFLOW;
459 exc.name = type < 100 ? "pow" : "powf";
461 if (_LIB_VERSION == _POSIX_)
463 else if (!matherr(&exc)) {
471 exc.name = type < 100 ? "pow" : "powf";
472 if (_LIB_VERSION == _SVID_)
475 exc.retval = -HUGE_VAL;
476 if (_LIB_VERSION == _POSIX_)
478 else if (!matherr(&exc)) {
479 if (_LIB_VERSION == _SVID_) {
480 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
487 /* neg**non-integral */
489 exc.name = type < 100 ? "pow" : "powf";
490 if (_LIB_VERSION == _SVID_)
493 exc.retval = zero/zero; /* X/Open allow NaN */
494 if (_LIB_VERSION == _POSIX_)
496 else if (!matherr(&exc)) {
497 if (_LIB_VERSION == _SVID_) {
498 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
505 /* sinh(finite) overflow */
507 exc.name = type < 100 ? "sinh" : "sinhf";
508 if (_LIB_VERSION == _SVID_)
509 exc.retval = ( (x>zero) ? HUGE : -HUGE);
511 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
512 if (_LIB_VERSION == _POSIX_)
514 else if (!matherr(&exc)) {
522 exc.name = type < 100 ? "sqrt" : "sqrtf";
523 if (_LIB_VERSION == _SVID_)
526 exc.retval = zero/zero;
527 if (_LIB_VERSION == _POSIX_)
529 else if (!matherr(&exc)) {
530 if (_LIB_VERSION == _SVID_) {
531 (void) WRITE2("sqrt: DOMAIN error\n", 19);
540 exc.name = type < 100 ? "fmod" : "fmodf";
541 if (_LIB_VERSION == _SVID_)
544 exc.retval = zero/zero;
545 if (_LIB_VERSION == _POSIX_)
547 else if (!matherr(&exc)) {
548 if (_LIB_VERSION == _SVID_) {
549 (void) WRITE2("fmod: DOMAIN error\n", 20);
558 exc.name = type < 100 ? "remainder" : "remainderf";
559 exc.retval = zero/zero;
560 if (_LIB_VERSION == _POSIX_)
562 else if (!matherr(&exc)) {
563 if (_LIB_VERSION == _SVID_) {
564 (void) WRITE2("remainder: DOMAIN error\n", 24);
573 exc.name = type < 100 ? "acosh" : "acoshf";
574 exc.retval = zero/zero;
575 if (_LIB_VERSION == _POSIX_)
577 else if (!matherr(&exc)) {
578 if (_LIB_VERSION == _SVID_) {
579 (void) WRITE2("acosh: DOMAIN error\n", 20);
588 exc.name = type < 100 ? "atanh" : "atanhf";
589 exc.retval = zero/zero;
590 if (_LIB_VERSION == _POSIX_)
592 else if (!matherr(&exc)) {
593 if (_LIB_VERSION == _SVID_) {
594 (void) WRITE2("atanh: DOMAIN error\n", 20);
603 exc.name = type < 100 ? "atanh" : "atanhf";
604 exc.retval = x/zero; /* sign(x)*inf */
605 if (_LIB_VERSION == _POSIX_)
607 else if (!matherr(&exc)) {
608 if (_LIB_VERSION == _SVID_) {
609 (void) WRITE2("atanh: SING error\n", 18);
616 /* scalb overflow; SVID also returns +-HUGE_VAL */
618 exc.name = type < 100 ? "scalb" : "scalbf";
619 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
620 if (_LIB_VERSION == _POSIX_)
622 else if (!matherr(&exc)) {
628 /* scalb underflow */
629 exc.type = UNDERFLOW;
630 exc.name = type < 100 ? "scalb" : "scalbf";
631 exc.retval = copysign(zero,x);
632 if (_LIB_VERSION == _POSIX_)
634 else if (!matherr(&exc)) {
640 /* j0(|x|>X_TLOSS) */
642 exc.name = type < 100 ? "j0" : "j0f";
644 if (_LIB_VERSION == _POSIX_)
646 else if (!matherr(&exc)) {
647 if (_LIB_VERSION == _SVID_) {
648 (void) WRITE2(exc.name, 2);
649 (void) WRITE2(": TLOSS error\n", 14);
658 exc.name = type < 100 ? "y0" : "y0f";
660 if (_LIB_VERSION == _POSIX_)
662 else if (!matherr(&exc)) {
663 if (_LIB_VERSION == _SVID_) {
664 (void) WRITE2(exc.name, 2);
665 (void) WRITE2(": TLOSS error\n", 14);
672 /* j1(|x|>X_TLOSS) */
674 exc.name = type < 100 ? "j1" : "j1f";
676 if (_LIB_VERSION == _POSIX_)
678 else if (!matherr(&exc)) {
679 if (_LIB_VERSION == _SVID_) {
680 (void) WRITE2(exc.name, 2);
681 (void) WRITE2(": TLOSS error\n", 14);
690 exc.name = type < 100 ? "y1" : "y1f";
692 if (_LIB_VERSION == _POSIX_)
694 else if (!matherr(&exc)) {
695 if (_LIB_VERSION == _SVID_) {
696 (void) WRITE2(exc.name, 2);
697 (void) WRITE2(": TLOSS error\n", 14);
704 /* jn(|x|>X_TLOSS) */
706 exc.name = type < 100 ? "jn" : "jnf";
708 if (_LIB_VERSION == _POSIX_)
710 else if (!matherr(&exc)) {
711 if (_LIB_VERSION == _SVID_) {
712 (void) WRITE2(exc.name, 2);
713 (void) WRITE2(": TLOSS error\n", 14);
722 exc.name = type < 100 ? "yn" : "ynf";
724 if (_LIB_VERSION == _POSIX_)
726 else if (!matherr(&exc)) {
727 if (_LIB_VERSION == _SVID_) {
728 (void) WRITE2(exc.name, 2);
729 (void) WRITE2(": TLOSS error\n", 14);
736 /* gamma(finite) overflow */
738 exc.name = type < 100 ? "gamma" : "gammaf";
739 if (_LIB_VERSION == _SVID_)
742 exc.retval = HUGE_VAL;
743 if (_LIB_VERSION == _POSIX_)
745 else if (!matherr(&exc)) {
751 /* gamma(-integer) or gamma(0) */
753 exc.name = type < 100 ? "gamma" : "gammaf";
754 if (_LIB_VERSION == _SVID_)
757 exc.retval = HUGE_VAL;
758 if (_LIB_VERSION == _POSIX_)
760 else if (!matherr(&exc)) {
761 if (_LIB_VERSION == _SVID_) {
762 (void) WRITE2("gamma: SING error\n", 18);
770 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
772 exc.name = type < 100 ? "pow" : "powf";
774 if (_LIB_VERSION == _IEEE_ ||
775 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
776 else if (!matherr(&exc)) {