1 /* @(#)k_standard.c 5.1 93/09/24 */ 2 /* 3 * ==================================================== 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 * 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 9 * is preserved. 10 * ==================================================== 11 */ 12 13 #include <sys/cdefs.h> 14 #if defined(LIBM_SCCS) && !defined(lint) 15 __RCSID("$NetBSD: k_standard.c,v 1.10 2001/05/26 16:49:58 aymeric Exp $"); 16 #endif 17 18 #include "math.h" 19 #include "math_private.h" 20 #include <errno.h> 21 22 #ifndef _USE_WRITE 23 #include <stdio.h> /* fputs(), stderr */ 24 #define WRITE2(u,v) fputs(u, stderr) 25 #else /* !defined(_USE_WRITE) */ 26 #include <unistd.h> /* write */ 27 #define WRITE2(u,v) write(2, u, v) 28 #undef fflush 29 #endif /* !defined(_USE_WRITE) */ 30 31 #ifdef __STDC__ 32 static const double zero = 0.0; /* used as const */ 33 #else 34 static double zero = 0.0; /* used as const */ 35 #endif 36 37 /* 38 * Standard conformance (non-IEEE) on exception cases. 39 * Mapping: 40 * 1 -- acos(|x|>1) 41 * 2 -- asin(|x|>1) 42 * 3 -- atan2(+-0,+-0) 43 * 4 -- hypot overflow 44 * 5 -- cosh overflow 45 * 6 -- exp overflow 46 * 7 -- exp underflow 47 * 8 -- y0(0) 48 * 9 -- y0(-ve) 49 * 10-- y1(0) 50 * 11-- y1(-ve) 51 * 12-- yn(0) 52 * 13-- yn(-ve) 53 * 14-- lgamma(finite) overflow 54 * 15-- lgamma(-integer) 55 * 16-- log(0) 56 * 17-- log(x<0) 57 * 18-- log10(0) 58 * 19-- log10(x<0) 59 * 20-- pow(0.0,0.0) 60 * 21-- pow(x,y) overflow 61 * 22-- pow(x,y) underflow 62 * 23-- pow(0,negative) 63 * 24-- pow(neg,non-integral) 64 * 25-- sinh(finite) overflow 65 * 26-- sqrt(negative) 66 * 27-- fmod(x,0) 67 * 28-- remainder(x,0) 68 * 29-- acosh(x<1) 69 * 30-- atanh(|x|>1) 70 * 31-- atanh(|x|=1) 71 * 32-- scalb overflow 72 * 33-- scalb underflow 73 * 34-- j0(|x|>X_TLOSS) 74 * 35-- y0(x>X_TLOSS) 75 * 36-- j1(|x|>X_TLOSS) 76 * 37-- y1(x>X_TLOSS) 77 * 38-- jn(|x|>X_TLOSS, n) 78 * 39-- yn(x>X_TLOSS, n) 79 * 40-- gamma(finite) overflow 80 * 41-- gamma(-integer) 81 * 42-- pow(NaN,0.0) 82 */ 83 84 85 #ifdef __STDC__ 86 double __kernel_standard(double x, double y, int type) 87 #else 88 double __kernel_standard(x,y,type) 89 double x,y; int type; 90 #endif 91 { 92 struct exception exc; 93 #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */ 94 #define HUGE_VAL inf 95 double inf = 0.0; 96 97 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ 98 #endif 99 100 #ifdef _USE_WRITE 101 (void) fflush(stdout); 102 #endif 103 exc.arg1 = x; 104 exc.arg2 = y; 105 switch(type) { 106 case 1: 107 case 101: 108 /* acos(|x|>1) */ 109 exc.type = DOMAIN; 110 exc.name = type < 100 ? "acos" : "acosf"; 111 exc.retval = zero; 112 if (_LIB_VERSION == _POSIX_) 113 errno = EDOM; 114 else if (!matherr(&exc)) { 115 if(_LIB_VERSION == _SVID_) { 116 (void) WRITE2("acos: DOMAIN error\n", 19); 117 } 118 errno = EDOM; 119 } 120 break; 121 case 2: 122 case 102: 123 /* asin(|x|>1) */ 124 exc.type = DOMAIN; 125 exc.name = type < 100 ? "asin" : "asinf"; 126 exc.retval = zero; 127 if(_LIB_VERSION == _POSIX_) 128 errno = EDOM; 129 else if (!matherr(&exc)) { 130 if(_LIB_VERSION == _SVID_) { 131 (void) WRITE2("asin: DOMAIN error\n", 19); 132 } 133 errno = EDOM; 134 } 135 break; 136 case 3: 137 case 103: 138 /* atan2(+-0,+-0) */ 139 exc.arg1 = y; 140 exc.arg2 = x; 141 exc.type = DOMAIN; 142 exc.name = type < 100 ? "atan2" : "atan2f"; 143 exc.retval = zero; 144 if(_LIB_VERSION == _POSIX_) 145 errno = EDOM; 146 else if (!matherr(&exc)) { 147 if(_LIB_VERSION == _SVID_) { 148 (void) WRITE2("atan2: DOMAIN error\n", 20); 149 } 150 errno = EDOM; 151 } 152 break; 153 case 4: 154 case 104: 155 /* hypot(finite,finite) overflow */ 156 exc.type = OVERFLOW; 157 exc.name = type < 100 ? "hypot" : "hypotf"; 158 if (_LIB_VERSION == _SVID_) 159 exc.retval = HUGE; 160 else 161 exc.retval = HUGE_VAL; 162 if (_LIB_VERSION == _POSIX_) 163 errno = ERANGE; 164 else if (!matherr(&exc)) { 165 errno = ERANGE; 166 } 167 break; 168 case 5: 169 case 105: 170 /* cosh(finite) overflow */ 171 exc.type = OVERFLOW; 172 exc.name = type < 100 ? "cosh" : "coshf"; 173 if (_LIB_VERSION == _SVID_) 174 exc.retval = HUGE; 175 else 176 exc.retval = HUGE_VAL; 177 if (_LIB_VERSION == _POSIX_) 178 errno = ERANGE; 179 else if (!matherr(&exc)) { 180 errno = ERANGE; 181 } 182 break; 183 case 6: 184 case 106: 185 /* exp(finite) overflow */ 186 exc.type = OVERFLOW; 187 exc.name = type < 100 ? "exp" : "expf"; 188 if (_LIB_VERSION == _SVID_) 189 exc.retval = HUGE; 190 else 191 exc.retval = HUGE_VAL; 192 if (_LIB_VERSION == _POSIX_) 193 errno = ERANGE; 194 else if (!matherr(&exc)) { 195 errno = ERANGE; 196 } 197 break; 198 case 7: 199 case 107: 200 /* exp(finite) underflow */ 201 exc.type = UNDERFLOW; 202 exc.name = type < 100 ? "exp" : "expf"; 203 exc.retval = zero; 204 if (_LIB_VERSION == _POSIX_) 205 errno = ERANGE; 206 else if (!matherr(&exc)) { 207 errno = ERANGE; 208 } 209 break; 210 case 8: 211 case 108: 212 /* y0(0) = -inf */ 213 exc.type = DOMAIN; /* should be SING for IEEE */ 214 exc.name = type < 100 ? "y0" : "y0f"; 215 if (_LIB_VERSION == _SVID_) 216 exc.retval = -HUGE; 217 else 218 exc.retval = -HUGE_VAL; 219 if (_LIB_VERSION == _POSIX_) 220 errno = EDOM; 221 else if (!matherr(&exc)) { 222 if (_LIB_VERSION == _SVID_) { 223 (void) WRITE2("y0: DOMAIN error\n", 17); 224 } 225 errno = EDOM; 226 } 227 break; 228 case 9: 229 case 109: 230 /* y0(x<0) = NaN */ 231 exc.type = DOMAIN; 232 exc.name = type < 100 ? "y0" : "y0f"; 233 if (_LIB_VERSION == _SVID_) 234 exc.retval = -HUGE; 235 else 236 exc.retval = -HUGE_VAL; 237 if (_LIB_VERSION == _POSIX_) 238 errno = EDOM; 239 else if (!matherr(&exc)) { 240 if (_LIB_VERSION == _SVID_) { 241 (void) WRITE2("y0: DOMAIN error\n", 17); 242 } 243 errno = EDOM; 244 } 245 break; 246 case 10: 247 case 110: 248 /* y1(0) = -inf */ 249 exc.type = DOMAIN; /* should be SING for IEEE */ 250 exc.name = type < 100 ? "y1" : "y1f"; 251 if (_LIB_VERSION == _SVID_) 252 exc.retval = -HUGE; 253 else 254 exc.retval = -HUGE_VAL; 255 if (_LIB_VERSION == _POSIX_) 256 errno = EDOM; 257 else if (!matherr(&exc)) { 258 if (_LIB_VERSION == _SVID_) { 259 (void) WRITE2("y1: DOMAIN error\n", 17); 260 } 261 errno = EDOM; 262 } 263 break; 264 case 11: 265 case 111: 266 /* y1(x<0) = NaN */ 267 exc.type = DOMAIN; 268 exc.name = type < 100 ? "y1" : "y1f"; 269 if (_LIB_VERSION == _SVID_) 270 exc.retval = -HUGE; 271 else 272 exc.retval = -HUGE_VAL; 273 if (_LIB_VERSION == _POSIX_) 274 errno = EDOM; 275 else if (!matherr(&exc)) { 276 if (_LIB_VERSION == _SVID_) { 277 (void) WRITE2("y1: DOMAIN error\n", 17); 278 } 279 errno = EDOM; 280 } 281 break; 282 case 12: 283 case 112: 284 /* yn(n,0) = -inf */ 285 exc.type = DOMAIN; /* should be SING for IEEE */ 286 exc.name = type < 100 ? "yn" : "ynf"; 287 if (_LIB_VERSION == _SVID_) 288 exc.retval = -HUGE; 289 else 290 exc.retval = -HUGE_VAL; 291 if (_LIB_VERSION == _POSIX_) 292 errno = EDOM; 293 else if (!matherr(&exc)) { 294 if (_LIB_VERSION == _SVID_) { 295 (void) WRITE2("yn: DOMAIN error\n", 17); 296 } 297 errno = EDOM; 298 } 299 break; 300 case 13: 301 case 113: 302 /* yn(x<0) = NaN */ 303 exc.type = DOMAIN; 304 exc.name = type < 100 ? "yn" : "ynf"; 305 if (_LIB_VERSION == _SVID_) 306 exc.retval = -HUGE; 307 else 308 exc.retval = -HUGE_VAL; 309 if (_LIB_VERSION == _POSIX_) 310 errno = EDOM; 311 else if (!matherr(&exc)) { 312 if (_LIB_VERSION == _SVID_) { 313 (void) WRITE2("yn: DOMAIN error\n", 17); 314 } 315 errno = EDOM; 316 } 317 break; 318 case 14: 319 case 114: 320 /* lgamma(finite) overflow */ 321 exc.type = OVERFLOW; 322 exc.name = type < 100 ? "lgamma" : "lgammaf"; 323 if (_LIB_VERSION == _SVID_) 324 exc.retval = HUGE; 325 else 326 exc.retval = HUGE_VAL; 327 if (_LIB_VERSION == _POSIX_) 328 errno = ERANGE; 329 else if (!matherr(&exc)) { 330 errno = ERANGE; 331 } 332 break; 333 case 15: 334 case 115: 335 /* lgamma(-integer) or lgamma(0) */ 336 exc.type = SING; 337 exc.name = type < 100 ? "lgamma" : "lgammaf"; 338 if (_LIB_VERSION == _SVID_) 339 exc.retval = HUGE; 340 else 341 exc.retval = HUGE_VAL; 342 if (_LIB_VERSION == _POSIX_) 343 errno = EDOM; 344 else if (!matherr(&exc)) { 345 if (_LIB_VERSION == _SVID_) { 346 (void) WRITE2("lgamma: SING error\n", 19); 347 } 348 errno = EDOM; 349 } 350 break; 351 case 16: 352 case 116: 353 /* log(0) */ 354 exc.type = SING; 355 exc.name = type < 100 ? "log" : "logf"; 356 if (_LIB_VERSION == _SVID_) 357 exc.retval = -HUGE; 358 else 359 exc.retval = -HUGE_VAL; 360 if (_LIB_VERSION == _POSIX_) 361 errno = ERANGE; 362 else if (!matherr(&exc)) { 363 if (_LIB_VERSION == _SVID_) { 364 (void) WRITE2("log: SING error\n", 16); 365 } 366 errno = EDOM; 367 } 368 break; 369 case 17: 370 case 117: 371 /* log(x<0) */ 372 exc.type = DOMAIN; 373 exc.name = type < 100 ? "log" : "logf"; 374 if (_LIB_VERSION == _SVID_) 375 exc.retval = -HUGE; 376 else 377 exc.retval = -HUGE_VAL; 378 if (_LIB_VERSION == _POSIX_) 379 errno = EDOM; 380 else if (!matherr(&exc)) { 381 if (_LIB_VERSION == _SVID_) { 382 (void) WRITE2("log: DOMAIN error\n", 18); 383 } 384 errno = EDOM; 385 } 386 break; 387 case 18: 388 case 118: 389 /* log10(0) */ 390 exc.type = SING; 391 exc.name = type < 100 ? "log10" : "log10f"; 392 if (_LIB_VERSION == _SVID_) 393 exc.retval = -HUGE; 394 else 395 exc.retval = -HUGE_VAL; 396 if (_LIB_VERSION == _POSIX_) 397 errno = ERANGE; 398 else if (!matherr(&exc)) { 399 if (_LIB_VERSION == _SVID_) { 400 (void) WRITE2("log10: SING error\n", 18); 401 } 402 errno = EDOM; 403 } 404 break; 405 case 19: 406 case 119: 407 /* log10(x<0) */ 408 exc.type = DOMAIN; 409 exc.name = type < 100 ? "log10" : "log10f"; 410 if (_LIB_VERSION == _SVID_) 411 exc.retval = -HUGE; 412 else 413 exc.retval = -HUGE_VAL; 414 if (_LIB_VERSION == _POSIX_) 415 errno = EDOM; 416 else if (!matherr(&exc)) { 417 if (_LIB_VERSION == _SVID_) { 418 (void) WRITE2("log10: DOMAIN error\n", 20); 419 } 420 errno = EDOM; 421 } 422 break; 423 case 20: 424 case 120: 425 /* pow(0.0,0.0) */ 426 /* error only if _LIB_VERSION == _SVID_ */ 427 exc.type = DOMAIN; 428 exc.name = type < 100 ? "pow" : "powf"; 429 exc.retval = zero; 430 if (_LIB_VERSION != _SVID_) exc.retval = 1.0; 431 else if (!matherr(&exc)) { 432 (void) WRITE2("pow(0,0): DOMAIN error\n", 23); 433 errno = EDOM; 434 } 435 break; 436 case 21: 437 case 121: 438 /* pow(x,y) overflow */ 439 exc.type = OVERFLOW; 440 exc.name = type < 100 ? "pow" : "powf"; 441 if (_LIB_VERSION == _SVID_) { 442 exc.retval = HUGE; 443 y *= 0.5; 444 if(x<zero&&rint(y)!=y) exc.retval = -HUGE; 445 } else { 446 exc.retval = HUGE_VAL; 447 y *= 0.5; 448 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL; 449 } 450 if (_LIB_VERSION == _POSIX_) 451 errno = ERANGE; 452 else if (!matherr(&exc)) { 453 errno = ERANGE; 454 } 455 break; 456 case 22: 457 case 122: 458 /* pow(x,y) underflow */ 459 exc.type = UNDERFLOW; 460 exc.name = type < 100 ? "pow" : "powf"; 461 exc.retval = zero; 462 if (_LIB_VERSION == _POSIX_) 463 errno = ERANGE; 464 else if (!matherr(&exc)) { 465 errno = ERANGE; 466 } 467 break; 468 case 23: 469 case 123: 470 /* 0**neg */ 471 exc.type = DOMAIN; 472 exc.name = type < 100 ? "pow" : "powf"; 473 if (_LIB_VERSION == _SVID_) 474 exc.retval = zero; 475 else 476 exc.retval = -HUGE_VAL; 477 if (_LIB_VERSION == _POSIX_) 478 errno = EDOM; 479 else if (!matherr(&exc)) { 480 if (_LIB_VERSION == _SVID_) { 481 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25); 482 } 483 errno = EDOM; 484 } 485 break; 486 case 24: 487 case 124: 488 /* neg**non-integral */ 489 exc.type = DOMAIN; 490 exc.name = type < 100 ? "pow" : "powf"; 491 if (_LIB_VERSION == _SVID_) 492 exc.retval = zero; 493 else 494 exc.retval = zero/zero; /* X/Open allow NaN */ 495 if (_LIB_VERSION == _POSIX_) 496 errno = EDOM; 497 else if (!matherr(&exc)) { 498 if (_LIB_VERSION == _SVID_) { 499 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32); 500 } 501 errno = EDOM; 502 } 503 break; 504 case 25: 505 case 125: 506 /* sinh(finite) overflow */ 507 exc.type = OVERFLOW; 508 exc.name = type < 100 ? "sinh" : "sinhf"; 509 if (_LIB_VERSION == _SVID_) 510 exc.retval = ( (x>zero) ? HUGE : -HUGE); 511 else 512 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL); 513 if (_LIB_VERSION == _POSIX_) 514 errno = ERANGE; 515 else if (!matherr(&exc)) { 516 errno = ERANGE; 517 } 518 break; 519 case 26: 520 case 126: 521 /* sqrt(x<0) */ 522 exc.type = DOMAIN; 523 exc.name = type < 100 ? "sqrt" : "sqrtf"; 524 if (_LIB_VERSION == _SVID_) 525 exc.retval = zero; 526 else 527 exc.retval = zero/zero; 528 if (_LIB_VERSION == _POSIX_) 529 errno = EDOM; 530 else if (!matherr(&exc)) { 531 if (_LIB_VERSION == _SVID_) { 532 (void) WRITE2("sqrt: DOMAIN error\n", 19); 533 } 534 errno = EDOM; 535 } 536 break; 537 case 27: 538 case 127: 539 /* fmod(x,0) */ 540 exc.type = DOMAIN; 541 exc.name = type < 100 ? "fmod" : "fmodf"; 542 if (_LIB_VERSION == _SVID_) 543 exc.retval = x; 544 else 545 exc.retval = zero/zero; 546 if (_LIB_VERSION == _POSIX_) 547 errno = EDOM; 548 else if (!matherr(&exc)) { 549 if (_LIB_VERSION == _SVID_) { 550 (void) WRITE2("fmod: DOMAIN error\n", 20); 551 } 552 errno = EDOM; 553 } 554 break; 555 case 28: 556 case 128: 557 /* remainder(x,0) */ 558 exc.type = DOMAIN; 559 exc.name = type < 100 ? "remainder" : "remainderf"; 560 exc.retval = zero/zero; 561 if (_LIB_VERSION == _POSIX_) 562 errno = EDOM; 563 else if (!matherr(&exc)) { 564 if (_LIB_VERSION == _SVID_) { 565 (void) WRITE2("remainder: DOMAIN error\n", 24); 566 } 567 errno = EDOM; 568 } 569 break; 570 case 29: 571 case 129: 572 /* acosh(x<1) */ 573 exc.type = DOMAIN; 574 exc.name = type < 100 ? "acosh" : "acoshf"; 575 exc.retval = zero/zero; 576 if (_LIB_VERSION == _POSIX_) 577 errno = EDOM; 578 else if (!matherr(&exc)) { 579 if (_LIB_VERSION == _SVID_) { 580 (void) WRITE2("acosh: DOMAIN error\n", 20); 581 } 582 errno = EDOM; 583 } 584 break; 585 case 30: 586 case 130: 587 /* atanh(|x|>1) */ 588 exc.type = DOMAIN; 589 exc.name = type < 100 ? "atanh" : "atanhf"; 590 exc.retval = zero/zero; 591 if (_LIB_VERSION == _POSIX_) 592 errno = EDOM; 593 else if (!matherr(&exc)) { 594 if (_LIB_VERSION == _SVID_) { 595 (void) WRITE2("atanh: DOMAIN error\n", 20); 596 } 597 errno = EDOM; 598 } 599 break; 600 case 31: 601 case 131: 602 /* atanh(|x|=1) */ 603 exc.type = SING; 604 exc.name = type < 100 ? "atanh" : "atanhf"; 605 exc.retval = x/zero; /* sign(x)*inf */ 606 if (_LIB_VERSION == _POSIX_) 607 errno = EDOM; 608 else if (!matherr(&exc)) { 609 if (_LIB_VERSION == _SVID_) { 610 (void) WRITE2("atanh: SING error\n", 18); 611 } 612 errno = EDOM; 613 } 614 break; 615 case 32: 616 case 132: 617 /* scalb overflow; SVID also returns +-HUGE_VAL */ 618 exc.type = OVERFLOW; 619 exc.name = type < 100 ? "scalb" : "scalbf"; 620 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL; 621 if (_LIB_VERSION == _POSIX_) 622 errno = ERANGE; 623 else if (!matherr(&exc)) { 624 errno = ERANGE; 625 } 626 break; 627 case 33: 628 case 133: 629 /* scalb underflow */ 630 exc.type = UNDERFLOW; 631 exc.name = type < 100 ? "scalb" : "scalbf"; 632 exc.retval = copysign(zero,x); 633 if (_LIB_VERSION == _POSIX_) 634 errno = ERANGE; 635 else if (!matherr(&exc)) { 636 errno = ERANGE; 637 } 638 break; 639 case 34: 640 case 134: 641 /* j0(|x|>X_TLOSS) */ 642 exc.type = TLOSS; 643 exc.name = type < 100 ? "j0" : "j0f"; 644 exc.retval = zero; 645 if (_LIB_VERSION == _POSIX_) 646 errno = ERANGE; 647 else if (!matherr(&exc)) { 648 if (_LIB_VERSION == _SVID_) { 649 (void) WRITE2(exc.name, 2); 650 (void) WRITE2(": TLOSS error\n", 14); 651 } 652 errno = ERANGE; 653 } 654 break; 655 case 35: 656 case 135: 657 /* y0(x>X_TLOSS) */ 658 exc.type = TLOSS; 659 exc.name = type < 100 ? "y0" : "y0f"; 660 exc.retval = zero; 661 if (_LIB_VERSION == _POSIX_) 662 errno = ERANGE; 663 else if (!matherr(&exc)) { 664 if (_LIB_VERSION == _SVID_) { 665 (void) WRITE2(exc.name, 2); 666 (void) WRITE2(": TLOSS error\n", 14); 667 } 668 errno = ERANGE; 669 } 670 break; 671 case 36: 672 case 136: 673 /* j1(|x|>X_TLOSS) */ 674 exc.type = TLOSS; 675 exc.name = type < 100 ? "j1" : "j1f"; 676 exc.retval = zero; 677 if (_LIB_VERSION == _POSIX_) 678 errno = ERANGE; 679 else if (!matherr(&exc)) { 680 if (_LIB_VERSION == _SVID_) { 681 (void) WRITE2(exc.name, 2); 682 (void) WRITE2(": TLOSS error\n", 14); 683 } 684 errno = ERANGE; 685 } 686 break; 687 case 37: 688 case 137: 689 /* y1(x>X_TLOSS) */ 690 exc.type = TLOSS; 691 exc.name = type < 100 ? "y1" : "y1f"; 692 exc.retval = zero; 693 if (_LIB_VERSION == _POSIX_) 694 errno = ERANGE; 695 else if (!matherr(&exc)) { 696 if (_LIB_VERSION == _SVID_) { 697 (void) WRITE2(exc.name, 2); 698 (void) WRITE2(": TLOSS error\n", 14); 699 } 700 errno = ERANGE; 701 } 702 break; 703 case 38: 704 case 138: 705 /* jn(|x|>X_TLOSS) */ 706 exc.type = TLOSS; 707 exc.name = type < 100 ? "jn" : "jnf"; 708 exc.retval = zero; 709 if (_LIB_VERSION == _POSIX_) 710 errno = ERANGE; 711 else if (!matherr(&exc)) { 712 if (_LIB_VERSION == _SVID_) { 713 (void) WRITE2(exc.name, 2); 714 (void) WRITE2(": TLOSS error\n", 14); 715 } 716 errno = ERANGE; 717 } 718 break; 719 case 39: 720 case 139: 721 /* yn(x>X_TLOSS) */ 722 exc.type = TLOSS; 723 exc.name = type < 100 ? "yn" : "ynf"; 724 exc.retval = zero; 725 if (_LIB_VERSION == _POSIX_) 726 errno = ERANGE; 727 else if (!matherr(&exc)) { 728 if (_LIB_VERSION == _SVID_) { 729 (void) WRITE2(exc.name, 2); 730 (void) WRITE2(": TLOSS error\n", 14); 731 } 732 errno = ERANGE; 733 } 734 break; 735 case 40: 736 case 140: 737 /* gamma(finite) overflow */ 738 exc.type = OVERFLOW; 739 exc.name = type < 100 ? "gamma" : "gammaf"; 740 if (_LIB_VERSION == _SVID_) 741 exc.retval = HUGE; 742 else 743 exc.retval = HUGE_VAL; 744 if (_LIB_VERSION == _POSIX_) 745 errno = ERANGE; 746 else if (!matherr(&exc)) { 747 errno = ERANGE; 748 } 749 break; 750 case 41: 751 case 141: 752 /* gamma(-integer) or gamma(0) */ 753 exc.type = SING; 754 exc.name = type < 100 ? "gamma" : "gammaf"; 755 if (_LIB_VERSION == _SVID_) 756 exc.retval = HUGE; 757 else 758 exc.retval = HUGE_VAL; 759 if (_LIB_VERSION == _POSIX_) 760 errno = EDOM; 761 else if (!matherr(&exc)) { 762 if (_LIB_VERSION == _SVID_) { 763 (void) WRITE2("gamma: SING error\n", 18); 764 } 765 errno = EDOM; 766 } 767 break; 768 case 42: 769 case 142: 770 /* pow(NaN,0.0) */ 771 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ 772 exc.type = DOMAIN; 773 exc.name = type < 100 ? "pow" : "powf"; 774 exc.retval = x; 775 if (_LIB_VERSION == _IEEE_ || 776 _LIB_VERSION == _POSIX_) exc.retval = 1.0; 777 else if (!matherr(&exc)) { 778 errno = EDOM; 779 } 780 break; 781 } 782 return exc.retval; 783 } 784