2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 #include "math_private.h"
19 #include <stdio.h> /* fputs(), stderr */
20 #define WRITE2(u,v) fputs(u, stderr)
21 #else /* !defined(_USE_WRITE) */
22 #include <unistd.h> /* write */
23 #define WRITE2(u,v) write(2, u, v)
25 #endif /* !defined(_USE_WRITE) */
27 static const double zero = 0.0; /* used as const */
30 * Standard conformance (non-IEEE) on exception cases.
45 * 14-- lgamma(finite) overflow
46 * 15-- lgamma(-integer)
52 * 21-- pow(x,y) overflow
53 * 22-- pow(x,y) underflow
54 * 23-- pow(0,negative)
55 * 24-- pow(neg,non-integral)
56 * 25-- sinh(finite) overflow
64 * 33-- scalb underflow
65 * 34-- j0(|x|>X_TLOSS)
67 * 36-- j1(|x|>X_TLOSS)
69 * 38-- jn(|x|>X_TLOSS, n)
70 * 39-- yn(x>X_TLOSS, n)
71 * 40-- gamma(finite) overflow
72 * 41-- gamma(-integer)
76 double __kernel_standard(double x, double y, int type)
79 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
83 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
87 (void) fflush(stdout);
96 exc.name = type < 100 ? "acos" : "acosf";
98 if (_LIB_VERSION == _POSIX_)
100 else if (!matherr(&exc)) {
101 if(_LIB_VERSION == _SVID_) {
102 (void) WRITE2("acos: DOMAIN error\n", 19);
111 exc.name = type < 100 ? "asin" : "asinf";
113 if(_LIB_VERSION == _POSIX_)
115 else if (!matherr(&exc)) {
116 if(_LIB_VERSION == _SVID_) {
117 (void) WRITE2("asin: DOMAIN error\n", 19);
128 exc.name = type < 100 ? "atan2" : "atan2f";
130 if(_LIB_VERSION == _POSIX_)
132 else if (!matherr(&exc)) {
133 if(_LIB_VERSION == _SVID_) {
134 (void) WRITE2("atan2: DOMAIN error\n", 20);
141 /* hypot(finite,finite) overflow */
143 exc.name = type < 100 ? "hypot" : "hypotf";
144 if (_LIB_VERSION == _SVID_)
147 exc.retval = HUGE_VAL;
148 if (_LIB_VERSION == _POSIX_)
150 else if (!matherr(&exc)) {
156 /* cosh(finite) overflow */
158 exc.name = type < 100 ? "cosh" : "coshf";
159 if (_LIB_VERSION == _SVID_)
162 exc.retval = HUGE_VAL;
163 if (_LIB_VERSION == _POSIX_)
165 else if (!matherr(&exc)) {
171 /* exp(finite) overflow */
173 exc.name = type < 100 ? "exp" : "expf";
174 if (_LIB_VERSION == _SVID_)
177 exc.retval = HUGE_VAL;
178 if (_LIB_VERSION == _POSIX_)
180 else if (!matherr(&exc)) {
186 /* exp(finite) underflow */
187 exc.type = UNDERFLOW;
188 exc.name = type < 100 ? "exp" : "expf";
190 if (_LIB_VERSION == _POSIX_)
192 else if (!matherr(&exc)) {
199 exc.type = DOMAIN; /* should be SING for IEEE */
200 exc.name = type < 100 ? "y0" : "y0f";
201 if (_LIB_VERSION == _SVID_)
204 exc.retval = -HUGE_VAL;
205 if (_LIB_VERSION == _POSIX_)
207 else if (!matherr(&exc)) {
208 if (_LIB_VERSION == _SVID_) {
209 (void) WRITE2("y0: DOMAIN error\n", 17);
218 exc.name = type < 100 ? "y0" : "y0f";
219 if (_LIB_VERSION == _SVID_)
222 exc.retval = -HUGE_VAL;
223 if (_LIB_VERSION == _POSIX_)
225 else if (!matherr(&exc)) {
226 if (_LIB_VERSION == _SVID_) {
227 (void) WRITE2("y0: DOMAIN error\n", 17);
235 exc.type = DOMAIN; /* should be SING for IEEE */
236 exc.name = type < 100 ? "y1" : "y1f";
237 if (_LIB_VERSION == _SVID_)
240 exc.retval = -HUGE_VAL;
241 if (_LIB_VERSION == _POSIX_)
243 else if (!matherr(&exc)) {
244 if (_LIB_VERSION == _SVID_) {
245 (void) WRITE2("y1: DOMAIN error\n", 17);
254 exc.name = type < 100 ? "y1" : "y1f";
255 if (_LIB_VERSION == _SVID_)
258 exc.retval = -HUGE_VAL;
259 if (_LIB_VERSION == _POSIX_)
261 else if (!matherr(&exc)) {
262 if (_LIB_VERSION == _SVID_) {
263 (void) WRITE2("y1: DOMAIN error\n", 17);
271 exc.type = DOMAIN; /* should be SING for IEEE */
272 exc.name = type < 100 ? "yn" : "ynf";
273 if (_LIB_VERSION == _SVID_)
276 exc.retval = -HUGE_VAL;
277 if (_LIB_VERSION == _POSIX_)
279 else if (!matherr(&exc)) {
280 if (_LIB_VERSION == _SVID_) {
281 (void) WRITE2("yn: DOMAIN error\n", 17);
290 exc.name = type < 100 ? "yn" : "ynf";
291 if (_LIB_VERSION == _SVID_)
294 exc.retval = -HUGE_VAL;
295 if (_LIB_VERSION == _POSIX_)
297 else if (!matherr(&exc)) {
298 if (_LIB_VERSION == _SVID_) {
299 (void) WRITE2("yn: DOMAIN error\n", 17);
306 /* lgamma(finite) overflow */
308 exc.name = type < 100 ? "lgamma" : "lgammaf";
309 if (_LIB_VERSION == _SVID_)
312 exc.retval = HUGE_VAL;
313 if (_LIB_VERSION == _POSIX_)
315 else if (!matherr(&exc)) {
321 /* lgamma(-integer) or lgamma(0) */
323 exc.name = type < 100 ? "lgamma" : "lgammaf";
324 if (_LIB_VERSION == _SVID_)
327 exc.retval = HUGE_VAL;
328 if (_LIB_VERSION == _POSIX_)
330 else if (!matherr(&exc)) {
331 if (_LIB_VERSION == _SVID_) {
332 (void) WRITE2("lgamma: SING error\n", 19);
341 exc.name = type < 100 ? "log" : "logf";
342 if (_LIB_VERSION == _SVID_)
345 exc.retval = -HUGE_VAL;
346 if (_LIB_VERSION == _POSIX_)
348 else if (!matherr(&exc)) {
349 if (_LIB_VERSION == _SVID_) {
350 (void) WRITE2("log: SING error\n", 16);
359 exc.name = type < 100 ? "log" : "logf";
360 if (_LIB_VERSION == _SVID_)
363 exc.retval = -HUGE_VAL;
364 if (_LIB_VERSION == _POSIX_)
366 else if (!matherr(&exc)) {
367 if (_LIB_VERSION == _SVID_) {
368 (void) WRITE2("log: DOMAIN error\n", 18);
377 exc.name = type < 100 ? "log10" : "log10f";
378 if (_LIB_VERSION == _SVID_)
381 exc.retval = -HUGE_VAL;
382 if (_LIB_VERSION == _POSIX_)
384 else if (!matherr(&exc)) {
385 if (_LIB_VERSION == _SVID_) {
386 (void) WRITE2("log10: SING error\n", 18);
395 exc.name = type < 100 ? "log10" : "log10f";
396 if (_LIB_VERSION == _SVID_)
399 exc.retval = -HUGE_VAL;
400 if (_LIB_VERSION == _POSIX_)
402 else if (!matherr(&exc)) {
403 if (_LIB_VERSION == _SVID_) {
404 (void) WRITE2("log10: DOMAIN error\n", 20);
412 /* error only if _LIB_VERSION == _SVID_ */
414 exc.name = type < 100 ? "pow" : "powf";
416 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
417 else if (!matherr(&exc)) {
418 (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
424 /* pow(x,y) overflow */
426 exc.name = type < 100 ? "pow" : "powf";
427 if (_LIB_VERSION == _SVID_) {
430 if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
432 exc.retval = HUGE_VAL;
434 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
436 if (_LIB_VERSION == _POSIX_)
438 else if (!matherr(&exc)) {
444 /* pow(x,y) underflow */
445 exc.type = UNDERFLOW;
446 exc.name = type < 100 ? "pow" : "powf";
448 if (_LIB_VERSION == _POSIX_)
450 else if (!matherr(&exc)) {
458 exc.name = type < 100 ? "pow" : "powf";
459 if (_LIB_VERSION == _SVID_)
462 exc.retval = -HUGE_VAL;
463 if (_LIB_VERSION == _POSIX_)
465 else if (!matherr(&exc)) {
466 if (_LIB_VERSION == _SVID_) {
467 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
474 /* neg**non-integral */
476 exc.name = type < 100 ? "pow" : "powf";
477 if (_LIB_VERSION == _SVID_)
480 exc.retval = zero/zero; /* X/Open allow NaN */
481 if (_LIB_VERSION == _POSIX_)
483 else if (!matherr(&exc)) {
484 if (_LIB_VERSION == _SVID_) {
485 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
492 /* sinh(finite) overflow */
494 exc.name = type < 100 ? "sinh" : "sinhf";
495 if (_LIB_VERSION == _SVID_)
496 exc.retval = ( (x>zero) ? HUGE : -HUGE);
498 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
499 if (_LIB_VERSION == _POSIX_)
501 else if (!matherr(&exc)) {
509 exc.name = type < 100 ? "sqrt" : "sqrtf";
510 if (_LIB_VERSION == _SVID_)
513 exc.retval = zero/zero;
514 if (_LIB_VERSION == _POSIX_)
516 else if (!matherr(&exc)) {
517 if (_LIB_VERSION == _SVID_) {
518 (void) WRITE2("sqrt: DOMAIN error\n", 19);
527 exc.name = type < 100 ? "fmod" : "fmodf";
528 if (_LIB_VERSION == _SVID_)
531 exc.retval = zero/zero;
532 if (_LIB_VERSION == _POSIX_)
534 else if (!matherr(&exc)) {
535 if (_LIB_VERSION == _SVID_) {
536 (void) WRITE2("fmod: DOMAIN error\n", 20);
545 exc.name = type < 100 ? "remainder" : "remainderf";
546 exc.retval = zero/zero;
547 if (_LIB_VERSION == _POSIX_)
549 else if (!matherr(&exc)) {
550 if (_LIB_VERSION == _SVID_) {
551 (void) WRITE2("remainder: DOMAIN error\n", 24);
560 exc.name = type < 100 ? "acosh" : "acoshf";
561 exc.retval = zero/zero;
562 if (_LIB_VERSION == _POSIX_)
564 else if (!matherr(&exc)) {
565 if (_LIB_VERSION == _SVID_) {
566 (void) WRITE2("acosh: DOMAIN error\n", 20);
575 exc.name = type < 100 ? "atanh" : "atanhf";
576 exc.retval = zero/zero;
577 if (_LIB_VERSION == _POSIX_)
579 else if (!matherr(&exc)) {
580 if (_LIB_VERSION == _SVID_) {
581 (void) WRITE2("atanh: DOMAIN error\n", 20);
590 exc.name = type < 100 ? "atanh" : "atanhf";
591 exc.retval = x/zero; /* sign(x)*inf */
592 if (_LIB_VERSION == _POSIX_)
594 else if (!matherr(&exc)) {
595 if (_LIB_VERSION == _SVID_) {
596 (void) WRITE2("atanh: SING error\n", 18);
603 /* scalb overflow; SVID also returns +-HUGE_VAL */
605 exc.name = type < 100 ? "scalb" : "scalbf";
606 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
607 if (_LIB_VERSION == _POSIX_)
609 else if (!matherr(&exc)) {
615 /* scalb underflow */
616 exc.type = UNDERFLOW;
617 exc.name = type < 100 ? "scalb" : "scalbf";
618 exc.retval = copysign(zero,x);
619 if (_LIB_VERSION == _POSIX_)
621 else if (!matherr(&exc)) {
627 /* j0(|x|>X_TLOSS) */
629 exc.name = type < 100 ? "j0" : "j0f";
631 if (_LIB_VERSION == _POSIX_)
633 else if (!matherr(&exc)) {
634 if (_LIB_VERSION == _SVID_) {
635 (void) WRITE2(exc.name, 2);
636 (void) WRITE2(": TLOSS error\n", 14);
645 exc.name = type < 100 ? "y0" : "y0f";
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);
659 /* j1(|x|>X_TLOSS) */
661 exc.name = type < 100 ? "j1" : "j1f";
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);
677 exc.name = type < 100 ? "y1" : "y1f";
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);
691 /* jn(|x|>X_TLOSS) */
693 exc.name = type < 100 ? "jn" : "jnf";
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);
709 exc.name = type < 100 ? "yn" : "ynf";
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);
723 /* gamma(finite) overflow */
725 exc.name = type < 100 ? "gamma" : "gammaf";
726 if (_LIB_VERSION == _SVID_)
729 exc.retval = HUGE_VAL;
730 if (_LIB_VERSION == _POSIX_)
732 else if (!matherr(&exc)) {
738 /* gamma(-integer) or gamma(0) */
740 exc.name = type < 100 ? "gamma" : "gammaf";
741 if (_LIB_VERSION == _SVID_)
744 exc.retval = HUGE_VAL;
745 if (_LIB_VERSION == _POSIX_)
747 else if (!matherr(&exc)) {
748 if (_LIB_VERSION == _SVID_) {
749 (void) WRITE2("gamma: SING error\n", 18);
757 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
759 exc.name = type < 100 ? "pow" : "powf";
761 if (_LIB_VERSION == _IEEE_ ||
762 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
763 else if (!matherr(&exc)) {
770 #endif /* _IEEE_LIBM */