29 #ifdef POK_NEEDS_LIBMATH
32 #include "math_private.h"
36 #ifdef POK_NEEDS_LIBC_STDIO
37 #include <libc/stdio.h>
38 #define WRITE2(u,v) printf (u)
44 #define WRITE2(u,v) write(2, u, v)
48 static const double zero = 0.0;
101 __kernel_standard(
double x,
double y,
int type)
104 #ifndef POK_ERRNO_HUGE_VAL
105 #define POK_ERRNO_HUGE_VAL inf
108 SET_HIGH_WORD(inf,0x7ff00000);
112 (void) fflush(stdout);
121 exc.name = type < 100 ?
"acos" :
"acosf";
123 if (_LIB_VERSION == _POSIX_)
124 errno = POK_ERRNO_EDOM;
125 else if (!matherr(&exc)) {
126 if(_LIB_VERSION == _SVID_) {
127 (void) WRITE2(
"acos: DOMAIN error\n", 19);
129 errno = POK_ERRNO_EDOM;
136 exc.name = type < 100 ?
"asin" :
"asinf";
138 if(_LIB_VERSION == _POSIX_)
139 errno = POK_ERRNO_EDOM;
140 else if (!matherr(&exc)) {
141 if(_LIB_VERSION == _SVID_) {
142 (void) WRITE2(
"asin: DOMAIN error\n", 19);
144 errno = POK_ERRNO_EDOM;
153 exc.name = type < 100 ?
"atan2" :
"atan2f";
155 if(_LIB_VERSION == _POSIX_)
156 errno = POK_ERRNO_EDOM;
157 else if (!matherr(&exc)) {
158 if(_LIB_VERSION == _SVID_) {
159 (void) WRITE2(
"atan2: DOMAIN error\n", 20);
161 errno = POK_ERRNO_EDOM;
168 exc.name = type < 100 ?
"hypot" :
"hypotf";
169 if (_LIB_VERSION == _SVID_)
170 exc.retval = POK_ERRNO_HUGE_VAL;
172 exc.retval = POK_ERRNO_HUGE_VAL;
173 if (_LIB_VERSION == _POSIX_)
174 errno = POK_ERRNO_ERANGE;
175 else if (!matherr(&exc)) {
176 errno = POK_ERRNO_ERANGE;
183 exc.name = type < 100 ?
"cosh" :
"coshf";
184 if (_LIB_VERSION == _SVID_)
185 exc.retval = POK_ERRNO_HUGE_VAL;
187 exc.retval = POK_ERRNO_HUGE_VAL;
188 if (_LIB_VERSION == _POSIX_)
189 errno = POK_ERRNO_ERANGE;
190 else if (!matherr(&exc)) {
191 errno = POK_ERRNO_ERANGE;
198 exc.name = type < 100 ?
"exp" :
"expf";
199 if (_LIB_VERSION == _SVID_)
200 exc.retval = POK_ERRNO_HUGE_VAL;
202 exc.retval = POK_ERRNO_HUGE_VAL;
203 if (_LIB_VERSION == _POSIX_)
204 errno = POK_ERRNO_ERANGE;
205 else if (!matherr(&exc)) {
206 errno = POK_ERRNO_ERANGE;
212 exc.type = UNDERFLOW;
213 exc.name = type < 100 ?
"exp" :
"expf";
215 if (_LIB_VERSION == _POSIX_)
216 errno = POK_ERRNO_ERANGE;
217 else if (!matherr(&exc)) {
218 errno = POK_ERRNO_ERANGE;
225 exc.name = type < 100 ?
"y0" :
"y0f";
226 if (_LIB_VERSION == _SVID_)
227 exc.retval = -POK_ERRNO_HUGE_VAL;
229 exc.retval = -POK_ERRNO_HUGE_VAL;
230 if (_LIB_VERSION == _POSIX_)
231 errno = POK_ERRNO_EDOM;
232 else if (!matherr(&exc)) {
233 if (_LIB_VERSION == _SVID_) {
234 (void) WRITE2(
"y0: DOMAIN error\n", 17);
236 errno = POK_ERRNO_EDOM;
243 exc.name = type < 100 ?
"y0" :
"y0f";
244 if (_LIB_VERSION == _SVID_)
245 exc.retval = -POK_ERRNO_HUGE_VAL;
247 exc.retval = -POK_ERRNO_HUGE_VAL;
248 if (_LIB_VERSION == _POSIX_)
249 errno = POK_ERRNO_EDOM;
250 else if (!matherr(&exc)) {
251 if (_LIB_VERSION == _SVID_) {
252 (void) WRITE2(
"y0: DOMAIN error\n", 17);
254 errno = POK_ERRNO_EDOM;
261 exc.name = type < 100 ?
"y1" :
"y1f";
262 if (_LIB_VERSION == _SVID_)
263 exc.retval = -POK_ERRNO_HUGE_VAL;
265 exc.retval = -POK_ERRNO_HUGE_VAL;
266 if (_LIB_VERSION == _POSIX_)
267 errno = POK_ERRNO_EDOM;
268 else if (!matherr(&exc)) {
269 if (_LIB_VERSION == _SVID_) {
270 (void) WRITE2(
"y1: DOMAIN error\n", 17);
272 errno = POK_ERRNO_EDOM;
279 exc.name = type < 100 ?
"y1" :
"y1f";
280 if (_LIB_VERSION == _SVID_)
281 exc.retval = -POK_ERRNO_HUGE_VAL;
283 exc.retval = -POK_ERRNO_HUGE_VAL;
284 if (_LIB_VERSION == _POSIX_)
285 errno = POK_ERRNO_EDOM;
286 else if (!matherr(&exc)) {
287 if (_LIB_VERSION == _SVID_) {
288 (void) WRITE2(
"y1: DOMAIN error\n", 17);
290 errno = POK_ERRNO_EDOM;
297 exc.name = type < 100 ?
"yn" :
"ynf";
298 if (_LIB_VERSION == _SVID_)
299 exc.retval = -POK_ERRNO_HUGE_VAL;
301 exc.retval = -POK_ERRNO_HUGE_VAL;
302 if (_LIB_VERSION == _POSIX_)
303 errno = POK_ERRNO_EDOM;
304 else if (!matherr(&exc)) {
305 if (_LIB_VERSION == _SVID_) {
306 (void) WRITE2(
"yn: DOMAIN error\n", 17);
308 errno = POK_ERRNO_EDOM;
315 exc.name = type < 100 ?
"yn" :
"ynf";
316 if (_LIB_VERSION == _SVID_)
317 exc.retval = -POK_ERRNO_HUGE_VAL;
319 exc.retval = -POK_ERRNO_HUGE_VAL;
320 if (_LIB_VERSION == _POSIX_)
321 errno = POK_ERRNO_EDOM;
322 else if (!matherr(&exc)) {
323 if (_LIB_VERSION == _SVID_) {
324 (void) WRITE2(
"yn: DOMAIN error\n", 17);
326 errno = POK_ERRNO_EDOM;
333 exc.name = type < 100 ?
"lgamma" :
"lgammaf";
334 if (_LIB_VERSION == _SVID_)
335 exc.retval = POK_ERRNO_HUGE_VAL;
337 exc.retval = POK_ERRNO_HUGE_VAL;
338 if (_LIB_VERSION == _POSIX_)
339 errno = POK_ERRNO_ERANGE;
340 else if (!matherr(&exc)) {
341 errno = POK_ERRNO_ERANGE;
348 exc.name = type < 100 ?
"lgamma" :
"lgammaf";
349 if (_LIB_VERSION == _SVID_)
350 exc.retval = POK_ERRNO_HUGE_VAL;
352 exc.retval = POK_ERRNO_HUGE_VAL;
353 if (_LIB_VERSION == _POSIX_)
354 errno = POK_ERRNO_EDOM;
355 else if (!matherr(&exc)) {
356 if (_LIB_VERSION == _SVID_) {
357 (void) WRITE2(
"lgamma: SING error\n", 19);
359 errno = POK_ERRNO_EDOM;
366 exc.name = type < 100 ?
"log" :
"logf";
367 if (_LIB_VERSION == _SVID_)
368 exc.retval = -POK_ERRNO_HUGE_VAL;
370 exc.retval = -POK_ERRNO_HUGE_VAL;
371 if (_LIB_VERSION == _POSIX_)
372 errno = POK_ERRNO_ERANGE;
373 else if (!matherr(&exc)) {
374 if (_LIB_VERSION == _SVID_) {
375 (void) WRITE2(
"log: SING error\n", 16);
377 errno = POK_ERRNO_EDOM;
384 exc.name = type < 100 ?
"log" :
"logf";
385 if (_LIB_VERSION == _SVID_)
386 exc.retval = -POK_ERRNO_HUGE_VAL;
388 exc.retval = -POK_ERRNO_HUGE_VAL;
389 if (_LIB_VERSION == _POSIX_)
390 errno = POK_ERRNO_EDOM;
391 else if (!matherr(&exc)) {
392 if (_LIB_VERSION == _SVID_) {
393 (void) WRITE2(
"log: DOMAIN error\n", 18);
395 errno = POK_ERRNO_EDOM;
402 exc.name = type < 100 ?
"log10" :
"log10f";
403 if (_LIB_VERSION == _SVID_)
404 exc.retval = -POK_ERRNO_HUGE_VAL;
406 exc.retval = -POK_ERRNO_HUGE_VAL;
407 if (_LIB_VERSION == _POSIX_)
408 errno = POK_ERRNO_ERANGE;
409 else if (!matherr(&exc)) {
410 if (_LIB_VERSION == _SVID_) {
411 (void) WRITE2(
"log10: SING error\n", 18);
413 errno = POK_ERRNO_EDOM;
420 exc.name = type < 100 ?
"log10" :
"log10f";
421 if (_LIB_VERSION == _SVID_)
422 exc.retval = -POK_ERRNO_HUGE_VAL;
424 exc.retval = -POK_ERRNO_HUGE_VAL;
425 if (_LIB_VERSION == _POSIX_)
426 errno = POK_ERRNO_EDOM;
427 else if (!matherr(&exc)) {
428 if (_LIB_VERSION == _SVID_) {
429 (void) WRITE2(
"log10: DOMAIN error\n", 20);
431 errno = POK_ERRNO_EDOM;
439 exc.name = type < 100 ?
"pow" :
"powf";
441 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
442 else if (!matherr(&exc)) {
443 (void) WRITE2(
"pow(0,0): DOMAIN error\n", 23);
444 errno = POK_ERRNO_EDOM;
451 exc.name = type < 100 ?
"pow" :
"powf";
452 if (_LIB_VERSION == _SVID_) {
453 exc.retval = POK_ERRNO_HUGE_VAL;
455 if(x<zero&&rint(y)!=y) exc.retval = -POK_ERRNO_HUGE_VAL;
457 exc.retval = POK_ERRNO_HUGE_VAL;
459 if(x<zero&&rint(y)!=y) exc.retval = -POK_ERRNO_HUGE_VAL;
461 if (_LIB_VERSION == _POSIX_)
462 errno = POK_ERRNO_ERANGE;
463 else if (!matherr(&exc)) {
464 errno = POK_ERRNO_ERANGE;
470 exc.type = UNDERFLOW;
471 exc.name = type < 100 ?
"pow" :
"powf";
473 if (_LIB_VERSION == _POSIX_)
474 errno = POK_ERRNO_ERANGE;
475 else if (!matherr(&exc)) {
476 errno = POK_ERRNO_ERANGE;
483 exc.name = type < 100 ?
"pow" :
"powf";
484 if (_LIB_VERSION == _SVID_)
487 exc.retval = -POK_ERRNO_HUGE_VAL;
488 if (_LIB_VERSION == _POSIX_)
489 errno = POK_ERRNO_EDOM;
490 else if (!matherr(&exc)) {
491 if (_LIB_VERSION == _SVID_) {
492 (void) WRITE2(
"pow(0,neg): DOMAIN error\n", 25);
494 errno = POK_ERRNO_EDOM;
501 exc.name = type < 100 ?
"pow" :
"powf";
502 if (_LIB_VERSION == _SVID_)
505 exc.retval = zero/zero;
506 if (_LIB_VERSION == _POSIX_)
507 errno = POK_ERRNO_EDOM;
508 else if (!matherr(&exc)) {
509 if (_LIB_VERSION == _SVID_) {
510 (void) WRITE2(
"neg**non-integral: DOMAIN error\n", 32);
512 errno = POK_ERRNO_EDOM;
519 exc.name = type < 100 ?
"sinh" :
"sinhf";
520 if (_LIB_VERSION == _SVID_)
521 exc.retval = ( (x>zero) ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL);
523 exc.retval = ( (x>zero) ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL);
524 if (_LIB_VERSION == _POSIX_)
525 errno = POK_ERRNO_ERANGE;
526 else if (!matherr(&exc)) {
527 errno = POK_ERRNO_ERANGE;
534 exc.name = type < 100 ?
"sqrt" :
"sqrtf";
535 if (_LIB_VERSION == _SVID_)
538 exc.retval = zero/zero;
539 if (_LIB_VERSION == _POSIX_)
540 errno = POK_ERRNO_EDOM;
541 else if (!matherr(&exc)) {
542 if (_LIB_VERSION == _SVID_) {
543 (void) WRITE2(
"sqrt: DOMAIN error\n", 19);
545 errno = POK_ERRNO_EDOM;
552 exc.name = type < 100 ?
"fmod" :
"fmodf";
553 if (_LIB_VERSION == _SVID_)
556 exc.retval = zero/zero;
557 if (_LIB_VERSION == _POSIX_)
558 errno = POK_ERRNO_EDOM;
559 else if (!matherr(&exc)) {
560 if (_LIB_VERSION == _SVID_) {
561 (void) WRITE2(
"fmod: DOMAIN error\n", 20);
563 errno = POK_ERRNO_EDOM;
570 exc.name = type < 100 ?
"remainder" :
"remainderf";
571 exc.retval = zero/zero;
572 if (_LIB_VERSION == _POSIX_)
573 errno = POK_ERRNO_EDOM;
574 else if (!matherr(&exc)) {
575 if (_LIB_VERSION == _SVID_) {
576 (void) WRITE2(
"remainder: DOMAIN error\n", 24);
578 errno = POK_ERRNO_EDOM;
585 exc.name = type < 100 ?
"acosh" :
"acoshf";
586 exc.retval = zero/zero;
587 if (_LIB_VERSION == _POSIX_)
588 errno = POK_ERRNO_EDOM;
589 else if (!matherr(&exc)) {
590 if (_LIB_VERSION == _SVID_) {
591 (void) WRITE2(
"acosh: DOMAIN error\n", 20);
593 errno = POK_ERRNO_EDOM;
600 exc.name = type < 100 ?
"atanh" :
"atanhf";
601 exc.retval = zero/zero;
602 if (_LIB_VERSION == _POSIX_)
603 errno = POK_ERRNO_EDOM;
604 else if (!matherr(&exc)) {
605 if (_LIB_VERSION == _SVID_) {
606 (void) WRITE2(
"atanh: DOMAIN error\n", 20);
608 errno = POK_ERRNO_EDOM;
615 exc.name = type < 100 ?
"atanh" :
"atanhf";
617 if (_LIB_VERSION == _POSIX_)
618 errno = POK_ERRNO_EDOM;
619 else if (!matherr(&exc)) {
620 if (_LIB_VERSION == _SVID_) {
621 (void) WRITE2(
"atanh: SING error\n", 18);
623 errno = POK_ERRNO_EDOM;
630 exc.name = type < 100 ?
"scalb" :
"scalbf";
631 exc.retval = x > zero ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL;
632 if (_LIB_VERSION == _POSIX_)
633 errno = POK_ERRNO_ERANGE;
634 else if (!matherr(&exc)) {
635 errno = POK_ERRNO_ERANGE;
641 exc.type = UNDERFLOW;
642 exc.name = type < 100 ?
"scalb" :
"scalbf";
643 exc.retval = copysign(zero,x);
644 if (_LIB_VERSION == _POSIX_)
645 errno = POK_ERRNO_ERANGE;
646 else if (!matherr(&exc)) {
647 errno = POK_ERRNO_ERANGE;
654 exc.name = type < 100 ?
"j0" :
"j0f";
656 if (_LIB_VERSION == _POSIX_)
657 errno = POK_ERRNO_ERANGE;
658 else if (!matherr(&exc)) {
659 if (_LIB_VERSION == _SVID_) {
660 (void) WRITE2(exc.name, 2);
661 (void) WRITE2(
": TLOSS error\n", 14);
663 errno = POK_ERRNO_ERANGE;
670 exc.name = type < 100 ?
"y0" :
"y0f";
672 if (_LIB_VERSION == _POSIX_)
673 errno = POK_ERRNO_ERANGE;
674 else if (!matherr(&exc)) {
675 if (_LIB_VERSION == _SVID_) {
676 (void) WRITE2(exc.name, 2);
677 (void) WRITE2(
": TLOSS error\n", 14);
679 errno = POK_ERRNO_ERANGE;
686 exc.name = type < 100 ?
"j1" :
"j1f";
688 if (_LIB_VERSION == _POSIX_)
689 errno = POK_ERRNO_ERANGE;
690 else if (!matherr(&exc)) {
691 if (_LIB_VERSION == _SVID_) {
692 (void) WRITE2(exc.name, 2);
693 (void) WRITE2(
": TLOSS error\n", 14);
695 errno = POK_ERRNO_ERANGE;
702 exc.name = type < 100 ?
"y1" :
"y1f";
704 if (_LIB_VERSION == _POSIX_)
705 errno = POK_ERRNO_ERANGE;
706 else if (!matherr(&exc)) {
707 if (_LIB_VERSION == _SVID_) {
708 (void) WRITE2(exc.name, 2);
709 (void) WRITE2(
": TLOSS error\n", 14);
711 errno = POK_ERRNO_ERANGE;
718 exc.name = type < 100 ?
"jn" :
"jnf";
720 if (_LIB_VERSION == _POSIX_)
721 errno = POK_ERRNO_ERANGE;
722 else if (!matherr(&exc)) {
723 if (_LIB_VERSION == _SVID_) {
724 (void) WRITE2(exc.name, 2);
725 (void) WRITE2(
": TLOSS error\n", 14);
727 errno = POK_ERRNO_ERANGE;
734 exc.name = type < 100 ?
"yn" :
"ynf";
736 if (_LIB_VERSION == _POSIX_)
737 errno = POK_ERRNO_ERANGE;
738 else if (!matherr(&exc)) {
739 if (_LIB_VERSION == _SVID_) {
740 (void) WRITE2(exc.name, 2);
741 (void) WRITE2(
": TLOSS error\n", 14);
743 errno = POK_ERRNO_ERANGE;
750 exc.name = type < 100 ?
"gamma" :
"gammaf";
751 if (_LIB_VERSION == _SVID_)
752 exc.retval = POK_ERRNO_HUGE_VAL;
754 exc.retval = POK_ERRNO_HUGE_VAL;
755 if (_LIB_VERSION == _POSIX_)
756 errno = POK_ERRNO_ERANGE;
757 else if (!matherr(&exc)) {
758 errno = POK_ERRNO_ERANGE;
765 exc.name = type < 100 ?
"gamma" :
"gammaf";
766 if (_LIB_VERSION == _SVID_)
767 exc.retval = POK_ERRNO_HUGE_VAL;
769 exc.retval = POK_ERRNO_HUGE_VAL;
770 if (_LIB_VERSION == _POSIX_)
771 errno = POK_ERRNO_EDOM;
772 else if (!matherr(&exc)) {
773 if (_LIB_VERSION == _SVID_) {
774 (void) WRITE2(
"gamma: SING error\n", 18);
776 errno = POK_ERRNO_EDOM;
784 exc.name = type < 100 ?
"pow" :
"powf";
786 if (_LIB_VERSION == _IEEE_ ||
787 _LIB_VERSION == _POSIX_) exc.retval = 1.0;
788 else if (!matherr(&exc)) {
789 errno = POK_ERRNO_EDOM;
796 exc.name = type < 100 ?
"log2" :
"log2f";
797 if (_LIB_VERSION == _SVID_)
798 exc.retval = -POK_ERRNO_HUGE_VAL;
800 exc.retval = -POK_ERRNO_HUGE_VAL;
801 if (_LIB_VERSION == _POSIX_)
802 errno = POK_ERRNO_ERANGE;
803 else if (!matherr(&exc)) {
804 if (_LIB_VERSION == _SVID_) {
805 (void) WRITE2(
"log2: SING error\n", 18);
807 errno = POK_ERRNO_EDOM;
814 exc.name = type < 100 ?
"log2" :
"log2f";
815 if (_LIB_VERSION == _SVID_)
816 exc.retval = -POK_ERRNO_HUGE_VAL;
818 exc.retval = -POK_ERRNO_HUGE_VAL;
819 if (_LIB_VERSION == _POSIX_)
820 errno = POK_ERRNO_EDOM;
821 else if (!matherr(&exc)) {
822 if (_LIB_VERSION == _SVID_) {
823 (void) WRITE2(
"log2: DOMAIN error\n", 20);
825 errno = POK_ERRNO_EDOM;
830 exc.retval = -POK_ERRNO_HUGE_VAL;