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 * ====================================================
12 * $FreeBSD: src/lib/msun/src/k_standard.c,v 1.5 1999/08/28 00:06:41 peter Exp $
13 * $DragonFly: src/lib/msun/src/Attic/k_standard.c,v 1.2 2003/06/17 04:26:53 dillon Exp $
17 #include "math_private.h"
21 #include <stdio.h> /* fputs(), stderr */
22 #define WRITE2(u,v) fputs(u, stderr)
23 #else /* !defined(_USE_WRITE) */
24 #include <unistd.h> /* write */
25 #define WRITE2(u,v) write(2, u, v)
27 #endif /* !defined(_USE_WRITE) */
30 static const double zero = 0.0; /* used as const */
32 static double zero = 0.0; /* used as const */
36 * Standard conformance (non-IEEE) on exception cases.
51 * 14-- lgamma(finite) overflow
52 * 15-- lgamma(-integer)
58 * 21-- pow(x,y) overflow
59 * 22-- pow(x,y) underflow
60 * 23-- pow(0,negative)
61 * 24-- pow(neg,non-integral)
62 * 25-- sinh(finite) overflow
70 * 33-- scalb underflow
71 * 34-- j0(|x|>X_TLOSS)
73 * 36-- j1(|x|>X_TLOSS)
75 * 38-- jn(|x|>X_TLOSS, n)
76 * 39-- yn(x>X_TLOSS, n)
77 * 40-- gamma(finite) overflow
78 * 41-- gamma(-integer)
84 double __kernel_standard(double x, double y, int type)
86 double __kernel_standard(x,y,type)
91 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
95 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
99 (void) fflush(stdout);
108 exc.name = type < 100 ? "acos" : "acosf";
110 if (_LIB_VERSION == _POSIX_)
112 else if (!matherr(&exc)) {
113 if(_LIB_VERSION == _SVID_) {
114 (void) WRITE2("acos: DOMAIN error\n", 19);
123 exc.name = type < 100 ? "asin" : "asinf";
125 if(_LIB_VERSION == _POSIX_)
127 else if (!matherr(&exc)) {
128 if(_LIB_VERSION == _SVID_) {
129 (void) WRITE2("asin: DOMAIN error\n", 19);
140 exc.name = type < 100 ? "atan2" : "atan2f";
142 if(_LIB_VERSION == _POSIX_)
144 else if (!matherr(&exc)) {
145 if(_LIB_VERSION == _SVID_) {
146 (void) WRITE2("atan2: DOMAIN error\n", 20);
153 /* hypot(finite,finite) overflow */
155 exc.name = type < 100 ? "hypot" : "hypotf";
156 if (_LIB_VERSION == _SVID_)
159 exc.retval = HUGE_VAL;
160 if (_LIB_VERSION == _POSIX_)
162 else if (!matherr(&exc)) {
168 /* cosh(finite) overflow */
170 exc.name = type < 100 ? "cosh" : "coshf";
171 if (_LIB_VERSION == _SVID_)
174 exc.retval = HUGE_VAL;
175 if (_LIB_VERSION == _POSIX_)
177 else if (!matherr(&exc)) {
183 /* exp(finite) overflow */
185 exc.name = type < 100 ? "exp" : "expf";
186 if (_LIB_VERSION == _SVID_)
189 exc.retval = HUGE_VAL;
190 if (_LIB_VERSION == _POSIX_)
192 else if (!matherr(&exc)) {
198 /* exp(finite) underflow */
199 exc.type = UNDERFLOW;
200 exc.name = type < 100 ? "exp" : "expf";
202 if (_LIB_VERSION == _POSIX_)
204 else if (!matherr(&exc)) {
211 exc.type = DOMAIN; /* should be SING for IEEE */
212 exc.name = type < 100 ? "y0" : "y0f";
213 if (_LIB_VERSION == _SVID_)
216 exc.retval = -HUGE_VAL;
217 if (_LIB_VERSION == _POSIX_)
219 else if (!matherr(&exc)) {
220 if (_LIB_VERSION == _SVID_) {
221 (void) WRITE2("y0: DOMAIN error\n", 17);
230 exc.name = type < 100 ? "y0" : "y0f";
231 if (_LIB_VERSION == _SVID_)
234 exc.retval = -HUGE_VAL;
235 if (_LIB_VERSION == _POSIX_)
237 else if (!matherr(&exc)) {
238 if (_LIB_VERSION == _SVID_) {
239 (void) WRITE2("y0: DOMAIN error\n", 17);
247 exc.type = DOMAIN; /* should be SING for IEEE */
248 exc.name = type < 100 ? "y1" : "y1f";
249 if (_LIB_VERSION == _SVID_)
252 exc.retval = -HUGE_VAL;
253 if (_LIB_VERSION == _POSIX_)
255 else if (!matherr(&exc)) {
256 if (_LIB_VERSION == _SVID_) {
257 (void) WRITE2("y1: DOMAIN error\n", 17);
266 exc.name = type < 100 ? "y1" : "y1f";
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);
283 exc.type = DOMAIN; /* should be SING for IEEE */
284 exc.name = type < 100 ? "yn" : "ynf";
285 if (_LIB_VERSION == _SVID_)
288 exc.retval = -HUGE_VAL;
289 if (_LIB_VERSION == _POSIX_)
291 else if (!matherr(&exc)) {
292 if (_LIB_VERSION == _SVID_) {
293 (void) WRITE2("yn: DOMAIN error\n", 17);
302 exc.name = type < 100 ? "yn" : "ynf";
303 if (_LIB_VERSION == _SVID_)
306 exc.retval = -HUGE_VAL;
307 if (_LIB_VERSION == _POSIX_)
309 else if (!matherr(&exc)) {
310 if (_LIB_VERSION == _SVID_) {
311 (void) WRITE2("yn: DOMAIN error\n", 17);
318 /* lgamma(finite) overflow */
320 exc.name = type < 100 ? "lgamma" : "lgammaf";
321 if (_LIB_VERSION == _SVID_)
324 exc.retval = HUGE_VAL;
325 if (_LIB_VERSION == _POSIX_)
327 else if (!matherr(&exc)) {
333 /* lgamma(-integer) or lgamma(0) */
335 exc.name = type < 100 ? "lgamma" : "lgammaf";
336 if (_LIB_VERSION == _SVID_)
339 exc.retval = HUGE_VAL;
340 if (_LIB_VERSION == _POSIX_)
342 else if (!matherr(&exc)) {
343 if (_LIB_VERSION == _SVID_) {
344 (void) WRITE2("lgamma: SING error\n", 19);
353 exc.name = type < 100 ? "log" : "logf";
354 if (_LIB_VERSION == _SVID_)
357 exc.retval = -HUGE_VAL;
358 if (_LIB_VERSION == _POSIX_)
360 else if (!matherr(&exc)) {
361 if (_LIB_VERSION == _SVID_) {
362 (void) WRITE2("log: SING error\n", 16);
371 exc.name = type < 100 ? "log" : "logf";
372 if (_LIB_VERSION == _SVID_)
375 exc.retval = -HUGE_VAL;
376 if (_LIB_VERSION == _POSIX_)
378 else if (!matherr(&exc)) {
379 if (_LIB_VERSION == _SVID_) {
380 (void) WRITE2("log: DOMAIN error\n", 18);
389 exc.name = type < 100 ? "log10" : "log10f";
390 if (_LIB_VERSION == _SVID_)
393 exc.retval = -HUGE_VAL;
394 if (_LIB_VERSION == _POSIX_)
396 else if (!matherr(&exc)) {
397 if (_LIB_VERSION == _SVID_) {
398 (void) WRITE2("log10: SING error\n", 18);
407 exc.name = type < 100 ? "log10" : "log10f";
408 if (_LIB_VERSION == _SVID_)
411 exc.retval = -HUGE_VAL;
412 if (_LIB_VERSION == _POSIX_)
414 else if (!matherr(&exc)) {
415 if (_LIB_VERSION == _SVID_) {
416 (void) WRITE2("log10: DOMAIN error\n", 20);
424 /* error only if _LIB_VERSION == _SVID_ */
426 exc.name = type < 100 ? "pow" : "powf";
428 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
429 else if (!matherr(&exc)) {
430 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
436 /* pow(x,y) overflow */
438 exc.name = type < 100 ? "pow" : "powf";
439 if (_LIB_VERSION == _SVID_) {
442 if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
444 exc.retval = HUGE_VAL;
446 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
448 if (_LIB_VERSION == _POSIX_)
450 else if (!matherr(&exc)) {
456 /* pow(x,y) underflow */
457 exc.type = UNDERFLOW;
458 exc.name = type < 100 ? "pow" : "powf";
460 if (_LIB_VERSION == _POSIX_)
462 else if (!matherr(&exc)) {
470 exc.name = type < 100 ? "pow" : "powf";
471 if (_LIB_VERSION == _SVID_)
474 exc.retval = -HUGE_VAL;
475 if (_LIB_VERSION == _POSIX_)
477 else if (!matherr(&exc)) {
478 if (_LIB_VERSION == _SVID_) {
479 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
486 /* neg**non-integral */
488 exc.name = type < 100 ? "pow" : "powf";
489 if (_LIB_VERSION == _SVID_)
492 exc.retval = zero/zero; /* X/Open allow NaN */
493 if (_LIB_VERSION == _POSIX_)
495 else if (!matherr(&exc)) {
496 if (_LIB_VERSION == _SVID_) {
497 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
504 /* sinh(finite) overflow */
506 exc.name = type < 100 ? "sinh" : "sinhf";
507 if (_LIB_VERSION == _SVID_)
508 exc.retval = ( (x>zero) ? HUGE : -HUGE);
510 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
511 if (_LIB_VERSION == _POSIX_)
513 else if (!matherr(&exc)) {
521 exc.name = type < 100 ? "sqrt" : "sqrtf";
522 if (_LIB_VERSION == _SVID_)
525 exc.retval = zero/zero;
526 if (_LIB_VERSION == _POSIX_)
528 else if (!matherr(&exc)) {
529 if (_LIB_VERSION == _SVID_) {
530 (void) WRITE2("sqrt: DOMAIN error\n", 19);
539 exc.name = type < 100 ? "fmod" : "fmodf";
540 if (_LIB_VERSION == _SVID_)
543 exc.retval = zero/zero;
544 if (_LIB_VERSION == _POSIX_)
546 else if (!matherr(&exc)) {
547 if (_LIB_VERSION == _SVID_) {
548 (void) WRITE2("fmod: DOMAIN error\n", 20);
557 exc.name = type < 100 ? "remainder" : "remainderf";
558 exc.retval = zero/zero;
559 if (_LIB_VERSION == _POSIX_)
561 else if (!matherr(&exc)) {
562 if (_LIB_VERSION == _SVID_) {
563 (void) WRITE2("remainder: DOMAIN error\n", 24);
572 exc.name = type < 100 ? "acosh" : "acoshf";
573 exc.retval = zero/zero;
574 if (_LIB_VERSION == _POSIX_)
576 else if (!matherr(&exc)) {
577 if (_LIB_VERSION == _SVID_) {
578 (void) WRITE2("acosh: DOMAIN error\n", 20);
587 exc.name = type < 100 ? "atanh" : "atanhf";
588 exc.retval = zero/zero;
589 if (_LIB_VERSION == _POSIX_)
591 else if (!matherr(&exc)) {
592 if (_LIB_VERSION == _SVID_) {
593 (void) WRITE2("atanh: DOMAIN error\n", 20);
602 exc.name = type < 100 ? "atanh" : "atanhf";
603 exc.retval = x/zero; /* sign(x)*inf */
604 if (_LIB_VERSION == _POSIX_)
606 else if (!matherr(&exc)) {
607 if (_LIB_VERSION == _SVID_) {
608 (void) WRITE2("atanh: SING error\n", 18);
615 /* scalb overflow; SVID also returns +-HUGE_VAL */
617 exc.name = type < 100 ? "scalb" : "scalbf";
618 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
619 if (_LIB_VERSION == _POSIX_)
621 else if (!matherr(&exc)) {
627 /* scalb underflow */
628 exc.type = UNDERFLOW;
629 exc.name = type < 100 ? "scalb" : "scalbf";
630 exc.retval = copysign(zero,x);
631 if (_LIB_VERSION == _POSIX_)
633 else if (!matherr(&exc)) {
639 /* j0(|x|>X_TLOSS) */
641 exc.name = type < 100 ? "j0" : "j0f";
643 if (_LIB_VERSION == _POSIX_)
645 else if (!matherr(&exc)) {
646 if (_LIB_VERSION == _SVID_) {
647 (void) WRITE2(exc.name, 2);
648 (void) WRITE2(": TLOSS error\n", 14);
657 exc.name = type < 100 ? "y0" : "y0f";
659 if (_LIB_VERSION == _POSIX_)
661 else if (!matherr(&exc)) {
662 if (_LIB_VERSION == _SVID_) {
663 (void) WRITE2(exc.name, 2);
664 (void) WRITE2(": TLOSS error\n", 14);
671 /* j1(|x|>X_TLOSS) */
673 exc.name = type < 100 ? "j1" : "j1f";
675 if (_LIB_VERSION == _POSIX_)
677 else if (!matherr(&exc)) {
678 if (_LIB_VERSION == _SVID_) {
679 (void) WRITE2(exc.name, 2);
680 (void) WRITE2(": TLOSS error\n", 14);
689 exc.name = type < 100 ? "y1" : "y1f";
691 if (_LIB_VERSION == _POSIX_)
693 else if (!matherr(&exc)) {
694 if (_LIB_VERSION == _SVID_) {
695 (void) WRITE2(exc.name, 2);
696 (void) WRITE2(": TLOSS error\n", 14);
703 /* jn(|x|>X_TLOSS) */
705 exc.name = type < 100 ? "jn" : "jnf";
707 if (_LIB_VERSION == _POSIX_)
709 else if (!matherr(&exc)) {
710 if (_LIB_VERSION == _SVID_) {
711 (void) WRITE2(exc.name, 2);
712 (void) WRITE2(": TLOSS error\n", 14);
721 exc.name = type < 100 ? "yn" : "ynf";
723 if (_LIB_VERSION == _POSIX_)
725 else if (!matherr(&exc)) {
726 if (_LIB_VERSION == _SVID_) {
727 (void) WRITE2(exc.name, 2);
728 (void) WRITE2(": TLOSS error\n", 14);
735 /* gamma(finite) overflow */
737 exc.name = type < 100 ? "gamma" : "gammaf";
738 if (_LIB_VERSION == _SVID_)
741 exc.retval = HUGE_VAL;
742 if (_LIB_VERSION == _POSIX_)
744 else if (!matherr(&exc)) {
750 /* gamma(-integer) or gamma(0) */
752 exc.name = type < 100 ? "gamma" : "gammaf";
753 if (_LIB_VERSION == _SVID_)
756 exc.retval = HUGE_VAL;
757 if (_LIB_VERSION == _POSIX_)
759 else if (!matherr(&exc)) {
760 if (_LIB_VERSION == _SVID_) {
761 (void) WRITE2("gamma: SING error\n", 18);
769 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
771 exc.name = type < 100 ? "pow" : "powf";
773 if (_LIB_VERSION == _IEEE_ ||
774 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
775 else if (!matherr(&exc)) {