POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Sat Jan 31 20:12:07 2009 00015 */ 00016 00017 /* @(#)k_standard.c 5.1 93/09/24 */ 00018 /* 00019 * ==================================================== 00020 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00021 * 00022 * Developed at SunPro, a Sun Microsystems, Inc. business. 00023 * Permission to use, copy, modify, and distribute this 00024 * software is freely granted, provided that this notice 00025 * is preserved. 00026 * ==================================================== 00027 */ 00028 00029 #ifdef POK_NEEDS_LIBMATH 00030 00031 #include <libm.h> 00032 #include "math_private.h" 00033 #include <errno.h> 00034 00035 #ifndef _USE_WRITE 00036 #ifdef POK_NEEDS_LIBC_STDIO 00037 #include <libc/stdio.h> 00038 #define WRITE2(u,v) printf (u) 00039 #else 00040 #define WRITE2(u,v) 00041 #endif /* POK_NEEDS_STDIO */ 00042 #else /* !defined(_USE_WRITE) */ 00043 #include <unistd.h> /* write */ 00044 #define WRITE2(u,v) write(2, u, v) 00045 #undef fflush 00046 #endif /* !defined(_USE_WRITE) */ 00047 00048 static const double zero = 0.0; /* used as const */ 00049 00050 /* 00051 * Standard conformance (non-IEEE) on exception cases. 00052 * Mapping: 00053 * 1 -- acos(|x|>1) 00054 * 2 -- asin(|x|>1) 00055 * 3 -- atan2(+-0,+-0) 00056 * 4 -- hypot overflow 00057 * 5 -- cosh overflow 00058 * 6 -- exp overflow 00059 * 7 -- exp underflow 00060 * 8 -- y0(0) 00061 * 9 -- y0(-ve) 00062 * 10-- y1(0) 00063 * 11-- y1(-ve) 00064 * 12-- yn(0) 00065 * 13-- yn(-ve) 00066 * 14-- lgamma(finite) overflow 00067 * 15-- lgamma(-integer) 00068 * 16-- log(0) 00069 * 17-- log(x<0) 00070 * 18-- log10(0) 00071 * 19-- log10(x<0) 00072 * 20-- pow(0.0,0.0) 00073 * 21-- pow(x,y) overflow 00074 * 22-- pow(x,y) underflow 00075 * 23-- pow(0,negative) 00076 * 24-- pow(neg,non-integral) 00077 * 25-- sinh(finite) overflow 00078 * 26-- sqrt(negative) 00079 * 27-- fmod(x,0) 00080 * 28-- remainder(x,0) 00081 * 29-- acosh(x<1) 00082 * 30-- atanh(|x|>1) 00083 * 31-- atanh(|x|=1) 00084 * 32-- scalb overflow 00085 * 33-- scalb underflow 00086 * 34-- j0(|x|>X_TLOSS) 00087 * 35-- y0(x>X_TLOSS) 00088 * 36-- j1(|x|>X_TLOSS) 00089 * 37-- y1(x>X_TLOSS) 00090 * 38-- jn(|x|>X_TLOSS, n) 00091 * 39-- yn(x>X_TLOSS, n) 00092 * 40-- gamma(finite) overflow 00093 * 41-- gamma(-integer) 00094 * 42-- pow(NaN,0.0) 00095 * 48-- log2(0) 00096 * 49-- log2(x<0) 00097 */ 00098 00099 00100 double 00101 __kernel_standard(double x, double y, int type) 00102 { 00103 struct exception exc; 00104 #ifndef POK_ERRNO_HUGE_VAL /* this is the only routine that uses POK_ERRNO_HUGE_VAL */ 00105 #define POK_ERRNO_HUGE_VAL inf 00106 double inf = 0.0; 00107 00108 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ 00109 #endif 00110 00111 #ifdef _USE_WRITE 00112 (void) fflush(stdout); 00113 #endif 00114 exc.arg1 = x; 00115 exc.arg2 = y; 00116 switch(type) { 00117 case 1: 00118 case 101: 00119 /* acos(|x|>1) */ 00120 exc.type = DOMAIN; 00121 exc.name = type < 100 ? "acos" : "acosf"; 00122 exc.retval = zero; 00123 if (_LIB_VERSION == _POSIX_) 00124 errno = POK_ERRNO_EDOM; 00125 else if (!matherr(&exc)) { 00126 if(_LIB_VERSION == _SVID_) { 00127 (void) WRITE2("acos: DOMAIN error\n", 19); 00128 } 00129 errno = POK_ERRNO_EDOM; 00130 } 00131 break; 00132 case 2: 00133 case 102: 00134 /* asin(|x|>1) */ 00135 exc.type = DOMAIN; 00136 exc.name = type < 100 ? "asin" : "asinf"; 00137 exc.retval = zero; 00138 if(_LIB_VERSION == _POSIX_) 00139 errno = POK_ERRNO_EDOM; 00140 else if (!matherr(&exc)) { 00141 if(_LIB_VERSION == _SVID_) { 00142 (void) WRITE2("asin: DOMAIN error\n", 19); 00143 } 00144 errno = POK_ERRNO_EDOM; 00145 } 00146 break; 00147 case 3: 00148 case 103: 00149 /* atan2(+-0,+-0) */ 00150 exc.arg1 = y; 00151 exc.arg2 = x; 00152 exc.type = DOMAIN; 00153 exc.name = type < 100 ? "atan2" : "atan2f"; 00154 exc.retval = zero; 00155 if(_LIB_VERSION == _POSIX_) 00156 errno = POK_ERRNO_EDOM; 00157 else if (!matherr(&exc)) { 00158 if(_LIB_VERSION == _SVID_) { 00159 (void) WRITE2("atan2: DOMAIN error\n", 20); 00160 } 00161 errno = POK_ERRNO_EDOM; 00162 } 00163 break; 00164 case 4: 00165 case 104: 00166 /* hypot(finite,finite) overflow */ 00167 exc.type = OVERFLOW; 00168 exc.name = type < 100 ? "hypot" : "hypotf"; 00169 if (_LIB_VERSION == _SVID_) 00170 exc.retval = POK_ERRNO_HUGE_VAL; 00171 else 00172 exc.retval = POK_ERRNO_HUGE_VAL; 00173 if (_LIB_VERSION == _POSIX_) 00174 errno = POK_ERRNO_ERANGE; 00175 else if (!matherr(&exc)) { 00176 errno = POK_ERRNO_ERANGE; 00177 } 00178 break; 00179 case 5: 00180 case 105: 00181 /* cosh(finite) overflow */ 00182 exc.type = OVERFLOW; 00183 exc.name = type < 100 ? "cosh" : "coshf"; 00184 if (_LIB_VERSION == _SVID_) 00185 exc.retval = POK_ERRNO_HUGE_VAL; 00186 else 00187 exc.retval = POK_ERRNO_HUGE_VAL; 00188 if (_LIB_VERSION == _POSIX_) 00189 errno = POK_ERRNO_ERANGE; 00190 else if (!matherr(&exc)) { 00191 errno = POK_ERRNO_ERANGE; 00192 } 00193 break; 00194 case 6: 00195 case 106: 00196 /* exp(finite) overflow */ 00197 exc.type = OVERFLOW; 00198 exc.name = type < 100 ? "exp" : "expf"; 00199 if (_LIB_VERSION == _SVID_) 00200 exc.retval = POK_ERRNO_HUGE_VAL; 00201 else 00202 exc.retval = POK_ERRNO_HUGE_VAL; 00203 if (_LIB_VERSION == _POSIX_) 00204 errno = POK_ERRNO_ERANGE; 00205 else if (!matherr(&exc)) { 00206 errno = POK_ERRNO_ERANGE; 00207 } 00208 break; 00209 case 7: 00210 case 107: 00211 /* exp(finite) underflow */ 00212 exc.type = UNDERFLOW; 00213 exc.name = type < 100 ? "exp" : "expf"; 00214 exc.retval = zero; 00215 if (_LIB_VERSION == _POSIX_) 00216 errno = POK_ERRNO_ERANGE; 00217 else if (!matherr(&exc)) { 00218 errno = POK_ERRNO_ERANGE; 00219 } 00220 break; 00221 case 8: 00222 case 108: 00223 /* y0(0) = -inf */ 00224 exc.type = DOMAIN; /* should be SING for IEEE */ 00225 exc.name = type < 100 ? "y0" : "y0f"; 00226 if (_LIB_VERSION == _SVID_) 00227 exc.retval = -POK_ERRNO_HUGE_VAL; 00228 else 00229 exc.retval = -POK_ERRNO_HUGE_VAL; 00230 if (_LIB_VERSION == _POSIX_) 00231 errno = POK_ERRNO_EDOM; 00232 else if (!matherr(&exc)) { 00233 if (_LIB_VERSION == _SVID_) { 00234 (void) WRITE2("y0: DOMAIN error\n", 17); 00235 } 00236 errno = POK_ERRNO_EDOM; 00237 } 00238 break; 00239 case 9: 00240 case 109: 00241 /* y0(x<0) = NaN */ 00242 exc.type = DOMAIN; 00243 exc.name = type < 100 ? "y0" : "y0f"; 00244 if (_LIB_VERSION == _SVID_) 00245 exc.retval = -POK_ERRNO_HUGE_VAL; 00246 else 00247 exc.retval = -POK_ERRNO_HUGE_VAL; 00248 if (_LIB_VERSION == _POSIX_) 00249 errno = POK_ERRNO_EDOM; 00250 else if (!matherr(&exc)) { 00251 if (_LIB_VERSION == _SVID_) { 00252 (void) WRITE2("y0: DOMAIN error\n", 17); 00253 } 00254 errno = POK_ERRNO_EDOM; 00255 } 00256 break; 00257 case 10: 00258 case 110: 00259 /* y1(0) = -inf */ 00260 exc.type = DOMAIN; /* should be SING for IEEE */ 00261 exc.name = type < 100 ? "y1" : "y1f"; 00262 if (_LIB_VERSION == _SVID_) 00263 exc.retval = -POK_ERRNO_HUGE_VAL; 00264 else 00265 exc.retval = -POK_ERRNO_HUGE_VAL; 00266 if (_LIB_VERSION == _POSIX_) 00267 errno = POK_ERRNO_EDOM; 00268 else if (!matherr(&exc)) { 00269 if (_LIB_VERSION == _SVID_) { 00270 (void) WRITE2("y1: DOMAIN error\n", 17); 00271 } 00272 errno = POK_ERRNO_EDOM; 00273 } 00274 break; 00275 case 11: 00276 case 111: 00277 /* y1(x<0) = NaN */ 00278 exc.type = DOMAIN; 00279 exc.name = type < 100 ? "y1" : "y1f"; 00280 if (_LIB_VERSION == _SVID_) 00281 exc.retval = -POK_ERRNO_HUGE_VAL; 00282 else 00283 exc.retval = -POK_ERRNO_HUGE_VAL; 00284 if (_LIB_VERSION == _POSIX_) 00285 errno = POK_ERRNO_EDOM; 00286 else if (!matherr(&exc)) { 00287 if (_LIB_VERSION == _SVID_) { 00288 (void) WRITE2("y1: DOMAIN error\n", 17); 00289 } 00290 errno = POK_ERRNO_EDOM; 00291 } 00292 break; 00293 case 12: 00294 case 112: 00295 /* yn(n,0) = -inf */ 00296 exc.type = DOMAIN; /* should be SING for IEEE */ 00297 exc.name = type < 100 ? "yn" : "ynf"; 00298 if (_LIB_VERSION == _SVID_) 00299 exc.retval = -POK_ERRNO_HUGE_VAL; 00300 else 00301 exc.retval = -POK_ERRNO_HUGE_VAL; 00302 if (_LIB_VERSION == _POSIX_) 00303 errno = POK_ERRNO_EDOM; 00304 else if (!matherr(&exc)) { 00305 if (_LIB_VERSION == _SVID_) { 00306 (void) WRITE2("yn: DOMAIN error\n", 17); 00307 } 00308 errno = POK_ERRNO_EDOM; 00309 } 00310 break; 00311 case 13: 00312 case 113: 00313 /* yn(x<0) = NaN */ 00314 exc.type = DOMAIN; 00315 exc.name = type < 100 ? "yn" : "ynf"; 00316 if (_LIB_VERSION == _SVID_) 00317 exc.retval = -POK_ERRNO_HUGE_VAL; 00318 else 00319 exc.retval = -POK_ERRNO_HUGE_VAL; 00320 if (_LIB_VERSION == _POSIX_) 00321 errno = POK_ERRNO_EDOM; 00322 else if (!matherr(&exc)) { 00323 if (_LIB_VERSION == _SVID_) { 00324 (void) WRITE2("yn: DOMAIN error\n", 17); 00325 } 00326 errno = POK_ERRNO_EDOM; 00327 } 00328 break; 00329 case 14: 00330 case 114: 00331 /* lgamma(finite) overflow */ 00332 exc.type = OVERFLOW; 00333 exc.name = type < 100 ? "lgamma" : "lgammaf"; 00334 if (_LIB_VERSION == _SVID_) 00335 exc.retval = POK_ERRNO_HUGE_VAL; 00336 else 00337 exc.retval = POK_ERRNO_HUGE_VAL; 00338 if (_LIB_VERSION == _POSIX_) 00339 errno = POK_ERRNO_ERANGE; 00340 else if (!matherr(&exc)) { 00341 errno = POK_ERRNO_ERANGE; 00342 } 00343 break; 00344 case 15: 00345 case 115: 00346 /* lgamma(-integer) or lgamma(0) */ 00347 exc.type = SING; 00348 exc.name = type < 100 ? "lgamma" : "lgammaf"; 00349 if (_LIB_VERSION == _SVID_) 00350 exc.retval = POK_ERRNO_HUGE_VAL; 00351 else 00352 exc.retval = POK_ERRNO_HUGE_VAL; 00353 if (_LIB_VERSION == _POSIX_) 00354 errno = POK_ERRNO_EDOM; 00355 else if (!matherr(&exc)) { 00356 if (_LIB_VERSION == _SVID_) { 00357 (void) WRITE2("lgamma: SING error\n", 19); 00358 } 00359 errno = POK_ERRNO_EDOM; 00360 } 00361 break; 00362 case 16: 00363 case 116: 00364 /* log(0) */ 00365 exc.type = SING; 00366 exc.name = type < 100 ? "log" : "logf"; 00367 if (_LIB_VERSION == _SVID_) 00368 exc.retval = -POK_ERRNO_HUGE_VAL; 00369 else 00370 exc.retval = -POK_ERRNO_HUGE_VAL; 00371 if (_LIB_VERSION == _POSIX_) 00372 errno = POK_ERRNO_ERANGE; 00373 else if (!matherr(&exc)) { 00374 if (_LIB_VERSION == _SVID_) { 00375 (void) WRITE2("log: SING error\n", 16); 00376 } 00377 errno = POK_ERRNO_EDOM; 00378 } 00379 break; 00380 case 17: 00381 case 117: 00382 /* log(x<0) */ 00383 exc.type = DOMAIN; 00384 exc.name = type < 100 ? "log" : "logf"; 00385 if (_LIB_VERSION == _SVID_) 00386 exc.retval = -POK_ERRNO_HUGE_VAL; 00387 else 00388 exc.retval = -POK_ERRNO_HUGE_VAL; 00389 if (_LIB_VERSION == _POSIX_) 00390 errno = POK_ERRNO_EDOM; 00391 else if (!matherr(&exc)) { 00392 if (_LIB_VERSION == _SVID_) { 00393 (void) WRITE2("log: DOMAIN error\n", 18); 00394 } 00395 errno = POK_ERRNO_EDOM; 00396 } 00397 break; 00398 case 18: 00399 case 118: 00400 /* log10(0) */ 00401 exc.type = SING; 00402 exc.name = type < 100 ? "log10" : "log10f"; 00403 if (_LIB_VERSION == _SVID_) 00404 exc.retval = -POK_ERRNO_HUGE_VAL; 00405 else 00406 exc.retval = -POK_ERRNO_HUGE_VAL; 00407 if (_LIB_VERSION == _POSIX_) 00408 errno = POK_ERRNO_ERANGE; 00409 else if (!matherr(&exc)) { 00410 if (_LIB_VERSION == _SVID_) { 00411 (void) WRITE2("log10: SING error\n", 18); 00412 } 00413 errno = POK_ERRNO_EDOM; 00414 } 00415 break; 00416 case 19: 00417 case 119: 00418 /* log10(x<0) */ 00419 exc.type = DOMAIN; 00420 exc.name = type < 100 ? "log10" : "log10f"; 00421 if (_LIB_VERSION == _SVID_) 00422 exc.retval = -POK_ERRNO_HUGE_VAL; 00423 else 00424 exc.retval = -POK_ERRNO_HUGE_VAL; 00425 if (_LIB_VERSION == _POSIX_) 00426 errno = POK_ERRNO_EDOM; 00427 else if (!matherr(&exc)) { 00428 if (_LIB_VERSION == _SVID_) { 00429 (void) WRITE2("log10: DOMAIN error\n", 20); 00430 } 00431 errno = POK_ERRNO_EDOM; 00432 } 00433 break; 00434 case 20: 00435 case 120: 00436 /* pow(0.0,0.0) */ 00437 /* error only if _LIB_VERSION == _SVID_ */ 00438 exc.type = DOMAIN; 00439 exc.name = type < 100 ? "pow" : "powf"; 00440 exc.retval = zero; 00441 if (_LIB_VERSION != _SVID_) exc.retval = 1.0; 00442 else if (!matherr(&exc)) { 00443 (void) WRITE2("pow(0,0): DOMAIN error\n", 23); 00444 errno = POK_ERRNO_EDOM; 00445 } 00446 break; 00447 case 21: 00448 case 121: 00449 /* pow(x,y) overflow */ 00450 exc.type = OVERFLOW; 00451 exc.name = type < 100 ? "pow" : "powf"; 00452 if (_LIB_VERSION == _SVID_) { 00453 exc.retval = POK_ERRNO_HUGE_VAL; 00454 y *= 0.5; 00455 if(x<zero&&rint(y)!=y) exc.retval = -POK_ERRNO_HUGE_VAL; 00456 } else { 00457 exc.retval = POK_ERRNO_HUGE_VAL; 00458 y *= 0.5; 00459 if(x<zero&&rint(y)!=y) exc.retval = -POK_ERRNO_HUGE_VAL; 00460 } 00461 if (_LIB_VERSION == _POSIX_) 00462 errno = POK_ERRNO_ERANGE; 00463 else if (!matherr(&exc)) { 00464 errno = POK_ERRNO_ERANGE; 00465 } 00466 break; 00467 case 22: 00468 case 122: 00469 /* pow(x,y) underflow */ 00470 exc.type = UNDERFLOW; 00471 exc.name = type < 100 ? "pow" : "powf"; 00472 exc.retval = zero; 00473 if (_LIB_VERSION == _POSIX_) 00474 errno = POK_ERRNO_ERANGE; 00475 else if (!matherr(&exc)) { 00476 errno = POK_ERRNO_ERANGE; 00477 } 00478 break; 00479 case 23: 00480 case 123: 00481 /* 0**neg */ 00482 exc.type = DOMAIN; 00483 exc.name = type < 100 ? "pow" : "powf"; 00484 if (_LIB_VERSION == _SVID_) 00485 exc.retval = zero; 00486 else 00487 exc.retval = -POK_ERRNO_HUGE_VAL; 00488 if (_LIB_VERSION == _POSIX_) 00489 errno = POK_ERRNO_EDOM; 00490 else if (!matherr(&exc)) { 00491 if (_LIB_VERSION == _SVID_) { 00492 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25); 00493 } 00494 errno = POK_ERRNO_EDOM; 00495 } 00496 break; 00497 case 24: 00498 case 124: 00499 /* neg**non-integral */ 00500 exc.type = DOMAIN; 00501 exc.name = type < 100 ? "pow" : "powf"; 00502 if (_LIB_VERSION == _SVID_) 00503 exc.retval = zero; 00504 else 00505 exc.retval = zero/zero; /* X/Open allow NaN */ 00506 if (_LIB_VERSION == _POSIX_) 00507 errno = POK_ERRNO_EDOM; 00508 else if (!matherr(&exc)) { 00509 if (_LIB_VERSION == _SVID_) { 00510 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32); 00511 } 00512 errno = POK_ERRNO_EDOM; 00513 } 00514 break; 00515 case 25: 00516 case 125: 00517 /* sinh(finite) overflow */ 00518 exc.type = OVERFLOW; 00519 exc.name = type < 100 ? "sinh" : "sinhf"; 00520 if (_LIB_VERSION == _SVID_) 00521 exc.retval = ( (x>zero) ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL); 00522 else 00523 exc.retval = ( (x>zero) ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL); 00524 if (_LIB_VERSION == _POSIX_) 00525 errno = POK_ERRNO_ERANGE; 00526 else if (!matherr(&exc)) { 00527 errno = POK_ERRNO_ERANGE; 00528 } 00529 break; 00530 case 26: 00531 case 126: 00532 /* sqrt(x<0) */ 00533 exc.type = DOMAIN; 00534 exc.name = type < 100 ? "sqrt" : "sqrtf"; 00535 if (_LIB_VERSION == _SVID_) 00536 exc.retval = zero; 00537 else 00538 exc.retval = zero/zero; 00539 if (_LIB_VERSION == _POSIX_) 00540 errno = POK_ERRNO_EDOM; 00541 else if (!matherr(&exc)) { 00542 if (_LIB_VERSION == _SVID_) { 00543 (void) WRITE2("sqrt: DOMAIN error\n", 19); 00544 } 00545 errno = POK_ERRNO_EDOM; 00546 } 00547 break; 00548 case 27: 00549 case 127: 00550 /* fmod(x,0) */ 00551 exc.type = DOMAIN; 00552 exc.name = type < 100 ? "fmod" : "fmodf"; 00553 if (_LIB_VERSION == _SVID_) 00554 exc.retval = x; 00555 else 00556 exc.retval = zero/zero; 00557 if (_LIB_VERSION == _POSIX_) 00558 errno = POK_ERRNO_EDOM; 00559 else if (!matherr(&exc)) { 00560 if (_LIB_VERSION == _SVID_) { 00561 (void) WRITE2("fmod: DOMAIN error\n", 20); 00562 } 00563 errno = POK_ERRNO_EDOM; 00564 } 00565 break; 00566 case 28: 00567 case 128: 00568 /* remainder(x,0) */ 00569 exc.type = DOMAIN; 00570 exc.name = type < 100 ? "remainder" : "remainderf"; 00571 exc.retval = zero/zero; 00572 if (_LIB_VERSION == _POSIX_) 00573 errno = POK_ERRNO_EDOM; 00574 else if (!matherr(&exc)) { 00575 if (_LIB_VERSION == _SVID_) { 00576 (void) WRITE2("remainder: DOMAIN error\n", 24); 00577 } 00578 errno = POK_ERRNO_EDOM; 00579 } 00580 break; 00581 case 29: 00582 case 129: 00583 /* acosh(x<1) */ 00584 exc.type = DOMAIN; 00585 exc.name = type < 100 ? "acosh" : "acoshf"; 00586 exc.retval = zero/zero; 00587 if (_LIB_VERSION == _POSIX_) 00588 errno = POK_ERRNO_EDOM; 00589 else if (!matherr(&exc)) { 00590 if (_LIB_VERSION == _SVID_) { 00591 (void) WRITE2("acosh: DOMAIN error\n", 20); 00592 } 00593 errno = POK_ERRNO_EDOM; 00594 } 00595 break; 00596 case 30: 00597 case 130: 00598 /* atanh(|x|>1) */ 00599 exc.type = DOMAIN; 00600 exc.name = type < 100 ? "atanh" : "atanhf"; 00601 exc.retval = zero/zero; 00602 if (_LIB_VERSION == _POSIX_) 00603 errno = POK_ERRNO_EDOM; 00604 else if (!matherr(&exc)) { 00605 if (_LIB_VERSION == _SVID_) { 00606 (void) WRITE2("atanh: DOMAIN error\n", 20); 00607 } 00608 errno = POK_ERRNO_EDOM; 00609 } 00610 break; 00611 case 31: 00612 case 131: 00613 /* atanh(|x|=1) */ 00614 exc.type = SING; 00615 exc.name = type < 100 ? "atanh" : "atanhf"; 00616 exc.retval = x/zero; /* sign(x)*inf */ 00617 if (_LIB_VERSION == _POSIX_) 00618 errno = POK_ERRNO_EDOM; 00619 else if (!matherr(&exc)) { 00620 if (_LIB_VERSION == _SVID_) { 00621 (void) WRITE2("atanh: SING error\n", 18); 00622 } 00623 errno = POK_ERRNO_EDOM; 00624 } 00625 break; 00626 case 32: 00627 case 132: 00628 /* scalb overflow; SVID also returns +-POK_ERRNO_HUGE_VAL */ 00629 exc.type = OVERFLOW; 00630 exc.name = type < 100 ? "scalb" : "scalbf"; 00631 exc.retval = x > zero ? POK_ERRNO_HUGE_VAL : -POK_ERRNO_HUGE_VAL; 00632 if (_LIB_VERSION == _POSIX_) 00633 errno = POK_ERRNO_ERANGE; 00634 else if (!matherr(&exc)) { 00635 errno = POK_ERRNO_ERANGE; 00636 } 00637 break; 00638 case 33: 00639 case 133: 00640 /* scalb underflow */ 00641 exc.type = UNDERFLOW; 00642 exc.name = type < 100 ? "scalb" : "scalbf"; 00643 exc.retval = copysign(zero,x); 00644 if (_LIB_VERSION == _POSIX_) 00645 errno = POK_ERRNO_ERANGE; 00646 else if (!matherr(&exc)) { 00647 errno = POK_ERRNO_ERANGE; 00648 } 00649 break; 00650 case 34: 00651 case 134: 00652 /* j0(|x|>X_TLOSS) */ 00653 exc.type = TLOSS; 00654 exc.name = type < 100 ? "j0" : "j0f"; 00655 exc.retval = zero; 00656 if (_LIB_VERSION == _POSIX_) 00657 errno = POK_ERRNO_ERANGE; 00658 else if (!matherr(&exc)) { 00659 if (_LIB_VERSION == _SVID_) { 00660 (void) WRITE2(exc.name, 2); 00661 (void) WRITE2(": TLOSS error\n", 14); 00662 } 00663 errno = POK_ERRNO_ERANGE; 00664 } 00665 break; 00666 case 35: 00667 case 135: 00668 /* y0(x>X_TLOSS) */ 00669 exc.type = TLOSS; 00670 exc.name = type < 100 ? "y0" : "y0f"; 00671 exc.retval = zero; 00672 if (_LIB_VERSION == _POSIX_) 00673 errno = POK_ERRNO_ERANGE; 00674 else if (!matherr(&exc)) { 00675 if (_LIB_VERSION == _SVID_) { 00676 (void) WRITE2(exc.name, 2); 00677 (void) WRITE2(": TLOSS error\n", 14); 00678 } 00679 errno = POK_ERRNO_ERANGE; 00680 } 00681 break; 00682 case 36: 00683 case 136: 00684 /* j1(|x|>X_TLOSS) */ 00685 exc.type = TLOSS; 00686 exc.name = type < 100 ? "j1" : "j1f"; 00687 exc.retval = zero; 00688 if (_LIB_VERSION == _POSIX_) 00689 errno = POK_ERRNO_ERANGE; 00690 else if (!matherr(&exc)) { 00691 if (_LIB_VERSION == _SVID_) { 00692 (void) WRITE2(exc.name, 2); 00693 (void) WRITE2(": TLOSS error\n", 14); 00694 } 00695 errno = POK_ERRNO_ERANGE; 00696 } 00697 break; 00698 case 37: 00699 case 137: 00700 /* y1(x>X_TLOSS) */ 00701 exc.type = TLOSS; 00702 exc.name = type < 100 ? "y1" : "y1f"; 00703 exc.retval = zero; 00704 if (_LIB_VERSION == _POSIX_) 00705 errno = POK_ERRNO_ERANGE; 00706 else if (!matherr(&exc)) { 00707 if (_LIB_VERSION == _SVID_) { 00708 (void) WRITE2(exc.name, 2); 00709 (void) WRITE2(": TLOSS error\n", 14); 00710 } 00711 errno = POK_ERRNO_ERANGE; 00712 } 00713 break; 00714 case 38: 00715 case 138: 00716 /* jn(|x|>X_TLOSS) */ 00717 exc.type = TLOSS; 00718 exc.name = type < 100 ? "jn" : "jnf"; 00719 exc.retval = zero; 00720 if (_LIB_VERSION == _POSIX_) 00721 errno = POK_ERRNO_ERANGE; 00722 else if (!matherr(&exc)) { 00723 if (_LIB_VERSION == _SVID_) { 00724 (void) WRITE2(exc.name, 2); 00725 (void) WRITE2(": TLOSS error\n", 14); 00726 } 00727 errno = POK_ERRNO_ERANGE; 00728 } 00729 break; 00730 case 39: 00731 case 139: 00732 /* yn(x>X_TLOSS) */ 00733 exc.type = TLOSS; 00734 exc.name = type < 100 ? "yn" : "ynf"; 00735 exc.retval = zero; 00736 if (_LIB_VERSION == _POSIX_) 00737 errno = POK_ERRNO_ERANGE; 00738 else if (!matherr(&exc)) { 00739 if (_LIB_VERSION == _SVID_) { 00740 (void) WRITE2(exc.name, 2); 00741 (void) WRITE2(": TLOSS error\n", 14); 00742 } 00743 errno = POK_ERRNO_ERANGE; 00744 } 00745 break; 00746 case 40: 00747 case 140: 00748 /* gamma(finite) overflow */ 00749 exc.type = OVERFLOW; 00750 exc.name = type < 100 ? "gamma" : "gammaf"; 00751 if (_LIB_VERSION == _SVID_) 00752 exc.retval = POK_ERRNO_HUGE_VAL; 00753 else 00754 exc.retval = POK_ERRNO_HUGE_VAL; 00755 if (_LIB_VERSION == _POSIX_) 00756 errno = POK_ERRNO_ERANGE; 00757 else if (!matherr(&exc)) { 00758 errno = POK_ERRNO_ERANGE; 00759 } 00760 break; 00761 case 41: 00762 case 141: 00763 /* gamma(-integer) or gamma(0) */ 00764 exc.type = SING; 00765 exc.name = type < 100 ? "gamma" : "gammaf"; 00766 if (_LIB_VERSION == _SVID_) 00767 exc.retval = POK_ERRNO_HUGE_VAL; 00768 else 00769 exc.retval = POK_ERRNO_HUGE_VAL; 00770 if (_LIB_VERSION == _POSIX_) 00771 errno = POK_ERRNO_EDOM; 00772 else if (!matherr(&exc)) { 00773 if (_LIB_VERSION == _SVID_) { 00774 (void) WRITE2("gamma: SING error\n", 18); 00775 } 00776 errno = POK_ERRNO_EDOM; 00777 } 00778 break; 00779 case 42: 00780 case 142: 00781 /* pow(NaN,0.0) */ 00782 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ 00783 exc.type = DOMAIN; 00784 exc.name = type < 100 ? "pow" : "powf"; 00785 exc.retval = x; 00786 if (_LIB_VERSION == _IEEE_ || 00787 _LIB_VERSION == _POSIX_) exc.retval = 1.0; 00788 else if (!matherr(&exc)) { 00789 errno = POK_ERRNO_EDOM; 00790 } 00791 break; 00792 case 48: 00793 case 148: 00794 /* log2(0) */ 00795 exc.type = SING; 00796 exc.name = type < 100 ? "log2" : "log2f"; 00797 if (_LIB_VERSION == _SVID_) 00798 exc.retval = -POK_ERRNO_HUGE_VAL; 00799 else 00800 exc.retval = -POK_ERRNO_HUGE_VAL; 00801 if (_LIB_VERSION == _POSIX_) 00802 errno = POK_ERRNO_ERANGE; 00803 else if (!matherr(&exc)) { 00804 if (_LIB_VERSION == _SVID_) { 00805 (void) WRITE2("log2: SING error\n", 18); 00806 } 00807 errno = POK_ERRNO_EDOM; 00808 } 00809 break; 00810 case 49: 00811 case 149: 00812 /* log2(x<0) */ 00813 exc.type = DOMAIN; 00814 exc.name = type < 100 ? "log2" : "log2f"; 00815 if (_LIB_VERSION == _SVID_) 00816 exc.retval = -POK_ERRNO_HUGE_VAL; 00817 else 00818 exc.retval = -POK_ERRNO_HUGE_VAL; 00819 if (_LIB_VERSION == _POSIX_) 00820 errno = POK_ERRNO_EDOM; 00821 else if (!matherr(&exc)) { 00822 if (_LIB_VERSION == _SVID_) { 00823 (void) WRITE2("log2: DOMAIN error\n", 20); 00824 } 00825 errno = POK_ERRNO_EDOM; 00826 } 00827 break; 00828 00829 default: 00830 exc.retval = -POK_ERRNO_HUGE_VAL; 00831 break; 00832 /* 00833 * Default case introduced for POK to avoid a warning 00834 */ 00835 } 00836 return exc.retval; 00837 } 00838 00839 #endif