Back to index

glibc  2.9
k_standard.c
Go to the documentation of this file.
00001 /* @(#)k_standard.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice
00009  * is preserved.
00010  * ====================================================
00011  */
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: k_standard.c,v 1.6 1995/05/10 20:46:35 jtc Exp $";
00015 #endif
00016 
00017 #include "math.h"
00018 #include "math_private.h"
00019 #include <errno.h>
00020 
00021 #include <assert.h>
00022 
00023 #ifndef _USE_WRITE
00024 #include <stdio.h>                 /* fputs(), stderr */
00025 #define       WRITE2(u,v)   fputs(u, stderr)
00026 #else  /* !defined(_USE_WRITE) */
00027 #include <unistd.h>                /* write */
00028 #define       WRITE2(u,v)   write(2, u, v)
00029 #undef fflush
00030 #endif /* !defined(_USE_WRITE) */
00031 
00032 /* XXX gcc versions until now don't delay the 0.0/0.0 division until
00033    runtime but produce NaN at copile time.  This is wrong since the
00034    exceptions are not set correctly.  */
00035 #if 0 && defined __STDC__
00036 static const double zero = 0.0;    /* used as const */
00037 #else
00038 static double zero = 0.0;   /* used as const */
00039 #endif
00040 
00041 /*
00042  * Standard conformance (non-IEEE) on exception cases.
00043  * Mapping:
00044  *     1 -- acos(|x|>1)
00045  *     2 -- asin(|x|>1)
00046  *     3 -- atan2(+-0,+-0)
00047  *     4 -- hypot overflow
00048  *     5 -- cosh overflow
00049  *     6 -- exp overflow
00050  *     7 -- exp underflow
00051  *     8 -- y0(0)
00052  *     9 -- y0(-ve)
00053  *     10-- y1(0)
00054  *     11-- y1(-ve)
00055  *     12-- yn(0)
00056  *     13-- yn(-ve)
00057  *     14-- lgamma(finite) overflow
00058  *     15-- lgamma(-integer)
00059  *     16-- log(0)
00060  *     17-- log(x<0)
00061  *     18-- log10(0)
00062  *     19-- log10(x<0)
00063  *     20-- pow(0.0,0.0)
00064  *     21-- pow(x,y) overflow
00065  *     22-- pow(x,y) underflow
00066  *     23-- pow(0,negative)
00067  *     24-- pow(neg,non-integral)
00068  *     25-- sinh(finite) overflow
00069  *     26-- sqrt(negative)
00070  *      27-- fmod(x,0)
00071  *      28-- remainder(x,0)
00072  *     29-- acosh(x<1)
00073  *     30-- atanh(|x|>1)
00074  *     31-- atanh(|x|=1)
00075  *     32-- scalb overflow
00076  *     33-- scalb underflow
00077  *     34-- j0(|x|>X_TLOSS)
00078  *     35-- y0(x>X_TLOSS)
00079  *     36-- j1(|x|>X_TLOSS)
00080  *     37-- y1(x>X_TLOSS)
00081  *     38-- jn(|x|>X_TLOSS, n)
00082  *     39-- yn(x>X_TLOSS, n)
00083  *     40-- tgamma(finite) overflow
00084  *     41-- tgamma(-integer)
00085  *     42-- pow(NaN,0.0)
00086  *     43-- +0**neg
00087  *     44-- exp2 overflow
00088  *     45-- exp2 underflow
00089  *     46-- exp10 overflow
00090  *     47-- exp10 underflow
00091  *     48-- log2(0)
00092  *     49-- log2(x<0)
00093  *     50-- tgamma(+-0)
00094  */
00095 
00096 
00097 #ifdef __STDC__
00098        double __kernel_standard(double x, double y, int type)
00099 #else
00100        double __kernel_standard(x,y,type)
00101        double x,y; int type;
00102 #endif
00103 {
00104        struct exception exc;
00105 #ifndef HUGE_VAL     /* this is the only routine that uses HUGE_VAL */
00106 #define HUGE_VAL inf
00107        double inf = 0.0;
00108 
00109        SET_HIGH_WORD(inf,0x7ff00000);     /* set inf to infinite */
00110 #endif
00111 
00112 #ifdef _USE_WRITE
00113        (void) fflush(stdout);
00114 #endif
00115        exc.arg1 = x;
00116        exc.arg2 = y;
00117        switch(type) {
00118            case 1:
00119            case 101:
00120            case 201:
00121               /* acos(|x|>1) */
00122               exc.type = DOMAIN;
00123               exc.name = type < 100 ? "acos" : (type < 200
00124                                             ? "acosf" : "acosl");;
00125               if (_LIB_VERSION == _SVID_)
00126                 exc.retval = HUGE;
00127               else
00128                 exc.retval = NAN;
00129               if (_LIB_VERSION == _POSIX_)
00130                 __set_errno (EDOM);
00131               else if (!matherr(&exc)) {
00132                 if(_LIB_VERSION == _SVID_) {
00133                   (void) WRITE2("acos: DOMAIN error\n", 19);
00134                 }
00135                 __set_errno (EDOM);
00136               }
00137               break;
00138            case 2:
00139            case 102:
00140            case 202:
00141               /* asin(|x|>1) */
00142               exc.type = DOMAIN;
00143               exc.name = type < 100 ? "asin" : (type < 200
00144                                             ? "asinf" : "asinl");
00145               if (_LIB_VERSION == _SVID_)
00146                 exc.retval = HUGE;
00147               else
00148                 exc.retval = NAN;
00149               if(_LIB_VERSION == _POSIX_)
00150                 __set_errno (EDOM);
00151               else if (!matherr(&exc)) {
00152                 if(_LIB_VERSION == _SVID_) {
00153                      (void) WRITE2("asin: DOMAIN error\n", 19);
00154                 }
00155                 __set_errno (EDOM);
00156               }
00157               break;
00158            case 3:
00159            case 103:
00160            case 203:
00161               /* atan2(+-0,+-0) */
00162               exc.arg1 = y;
00163               exc.arg2 = x;
00164               exc.type = DOMAIN;
00165               exc.name = type < 100 ? "atan2" : (type < 200
00166                                              ? "atan2f" : "atan2l");
00167               assert (_LIB_VERSION == _SVID_);
00168               exc.retval = HUGE;
00169               if(_LIB_VERSION == _POSIX_)
00170                 __set_errno (EDOM);
00171               else if (!matherr(&exc)) {
00172                 if(_LIB_VERSION == _SVID_) {
00173                      (void) WRITE2("atan2: DOMAIN error\n", 20);
00174                     }
00175                 __set_errno (EDOM);
00176               }
00177               break;
00178            case 4:
00179            case 104:
00180            case 204:
00181               /* hypot(finite,finite) overflow */
00182               exc.type = OVERFLOW;
00183               exc.name = type < 100 ? "hypot" : (type < 200
00184                                              ? "hypotf" : "hypotl");
00185               if (_LIB_VERSION == _SVID_)
00186                 exc.retval = HUGE;
00187               else
00188                 exc.retval = HUGE_VAL;
00189               if (_LIB_VERSION == _POSIX_)
00190                 __set_errno (ERANGE);
00191               else if (!matherr(&exc)) {
00192                      __set_errno (ERANGE);
00193               }
00194               break;
00195            case 5:
00196            case 105:
00197            case 205:
00198               /* cosh(finite) overflow */
00199               exc.type = OVERFLOW;
00200               exc.name = type < 100 ? "cosh" : (type < 200
00201                                             ? "coshf" : "coshl");
00202               if (_LIB_VERSION == _SVID_)
00203                 exc.retval = HUGE;
00204               else
00205                 exc.retval = HUGE_VAL;
00206               if (_LIB_VERSION == _POSIX_)
00207                 __set_errno (ERANGE);
00208               else if (!matherr(&exc)) {
00209                      __set_errno (ERANGE);
00210               }
00211               break;
00212            case 6:
00213            case 106:
00214            case 206:
00215               /* exp(finite) overflow */
00216               exc.type = OVERFLOW;
00217               exc.name = type < 100 ? "exp" : (type < 200
00218                                            ? "expf" : "expl");
00219               if (_LIB_VERSION == _SVID_)
00220                 exc.retval = HUGE;
00221               else
00222                 exc.retval = HUGE_VAL;
00223               if (_LIB_VERSION == _POSIX_)
00224                 __set_errno (ERANGE);
00225               else if (!matherr(&exc)) {
00226                      __set_errno (ERANGE);
00227               }
00228               break;
00229            case 7:
00230            case 107:
00231            case 207:
00232               /* exp(finite) underflow */
00233               exc.type = UNDERFLOW;
00234               exc.name = type < 100 ? "exp" : (type < 200
00235                                            ? "expf" : "expl");
00236               exc.retval = zero;
00237               if (_LIB_VERSION == _POSIX_)
00238                 __set_errno (ERANGE);
00239               else if (!matherr(&exc)) {
00240                      __set_errno (ERANGE);
00241               }
00242               break;
00243            case 8:
00244            case 108:
00245            case 208:
00246               /* y0(0) = -inf */
00247               exc.type = DOMAIN;   /* should be SING for IEEE */
00248               exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
00249               if (_LIB_VERSION == _SVID_)
00250                 exc.retval = -HUGE;
00251               else
00252                 exc.retval = -HUGE_VAL;
00253               if (_LIB_VERSION == _POSIX_)
00254                 __set_errno (EDOM);
00255               else if (!matherr(&exc)) {
00256                 if (_LIB_VERSION == _SVID_) {
00257                      (void) WRITE2("y0: DOMAIN error\n", 17);
00258                     }
00259                 __set_errno (EDOM);
00260               }
00261               break;
00262            case 9:
00263            case 109:
00264            case 209:
00265               /* y0(x<0) = NaN */
00266               exc.type = DOMAIN;
00267               exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
00268               if (_LIB_VERSION == _SVID_)
00269                 exc.retval = -HUGE;
00270               else
00271                 exc.retval = -HUGE_VAL;
00272               if (_LIB_VERSION == _POSIX_)
00273                 __set_errno (EDOM);
00274               else if (!matherr(&exc)) {
00275                 if (_LIB_VERSION == _SVID_) {
00276                      (void) WRITE2("y0: DOMAIN error\n", 17);
00277                     }
00278                 __set_errno (EDOM);
00279               }
00280               break;
00281            case 10:
00282            case 110:
00283            case 210:
00284               /* y1(0) = -inf */
00285               exc.type = DOMAIN;   /* should be SING for IEEE */
00286               exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
00287               if (_LIB_VERSION == _SVID_)
00288                 exc.retval = -HUGE;
00289               else
00290                 exc.retval = -HUGE_VAL;
00291               if (_LIB_VERSION == _POSIX_)
00292                 __set_errno (EDOM);
00293               else if (!matherr(&exc)) {
00294                 if (_LIB_VERSION == _SVID_) {
00295                      (void) WRITE2("y1: DOMAIN error\n", 17);
00296                     }
00297                 __set_errno (EDOM);
00298               }
00299               break;
00300            case 11:
00301            case 111:
00302            case 211:
00303               /* y1(x<0) = NaN */
00304               exc.type = DOMAIN;
00305               exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
00306               if (_LIB_VERSION == _SVID_)
00307                 exc.retval = -HUGE;
00308               else
00309                 exc.retval = -HUGE_VAL;
00310               if (_LIB_VERSION == _POSIX_)
00311                 __set_errno (EDOM);
00312               else if (!matherr(&exc)) {
00313                 if (_LIB_VERSION == _SVID_) {
00314                      (void) WRITE2("y1: DOMAIN error\n", 17);
00315                     }
00316                 __set_errno (EDOM);
00317               }
00318               break;
00319            case 12:
00320            case 112:
00321            case 212:
00322               /* yn(n,0) = -inf */
00323               exc.type = DOMAIN;   /* should be SING for IEEE */
00324               exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
00325               if (_LIB_VERSION == _SVID_)
00326                 exc.retval = -HUGE;
00327               else
00328                 exc.retval = -HUGE_VAL;
00329               if (_LIB_VERSION == _POSIX_)
00330                 __set_errno (EDOM);
00331               else if (!matherr(&exc)) {
00332                 if (_LIB_VERSION == _SVID_) {
00333                      (void) WRITE2("yn: DOMAIN error\n", 17);
00334                     }
00335                 __set_errno (EDOM);
00336               }
00337               break;
00338            case 13:
00339            case 113:
00340            case 213:
00341               /* yn(x<0) = NaN */
00342               exc.type = DOMAIN;
00343               exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
00344               if (_LIB_VERSION == _SVID_)
00345                 exc.retval = -HUGE;
00346               else
00347                 exc.retval = -HUGE_VAL;
00348               if (_LIB_VERSION == _POSIX_)
00349                 __set_errno (EDOM);
00350               else if (!matherr(&exc)) {
00351                 if (_LIB_VERSION == _SVID_) {
00352                      (void) WRITE2("yn: DOMAIN error\n", 17);
00353                     }
00354                 __set_errno (EDOM);
00355               }
00356               break;
00357            case 14:
00358            case 114:
00359            case 214:
00360               /* lgamma(finite) overflow */
00361               exc.type = OVERFLOW;
00362               exc.name = type < 100 ? "lgamma" : (type < 200
00363                                               ? "lgammaf" : "lgammal");
00364                 if (_LIB_VERSION == _SVID_)
00365                   exc.retval = HUGE;
00366                 else
00367                   exc.retval = HUGE_VAL;
00368                 if (_LIB_VERSION == _POSIX_)
00369                      __set_errno (ERANGE);
00370                 else if (!matherr(&exc)) {
00371                         __set_errno (ERANGE);
00372               }
00373               break;
00374            case 15:
00375            case 115:
00376            case 215:
00377               /* lgamma(-integer) or lgamma(0) */
00378               exc.type = SING;
00379               exc.name = type < 100 ? "lgamma" : (type < 200
00380                                               ? "lgammaf" : "lgammal");
00381                 if (_LIB_VERSION == _SVID_)
00382                   exc.retval = HUGE;
00383                 else
00384                   exc.retval = HUGE_VAL;
00385               if (_LIB_VERSION == _POSIX_)
00386                 __set_errno (EDOM);
00387               else if (!matherr(&exc)) {
00388                 if (_LIB_VERSION == _SVID_) {
00389                      (void) WRITE2("lgamma: SING error\n", 19);
00390                     }
00391                 __set_errno (EDOM);
00392               }
00393               break;
00394            case 16:
00395            case 116:
00396            case 216:
00397               /* log(0) */
00398               exc.type = SING;
00399               exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
00400               if (_LIB_VERSION == _SVID_)
00401                 exc.retval = -HUGE;
00402               else
00403                 exc.retval = -HUGE_VAL;
00404               if (_LIB_VERSION == _POSIX_)
00405                 __set_errno (ERANGE);
00406               else if (!matherr(&exc)) {
00407                 if (_LIB_VERSION == _SVID_) {
00408                      (void) WRITE2("log: SING error\n", 16);
00409                     }
00410                 __set_errno (EDOM);
00411               }
00412               break;
00413            case 17:
00414            case 117:
00415            case 217:
00416               /* log(x<0) */
00417               exc.type = DOMAIN;
00418               exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
00419               if (_LIB_VERSION == _SVID_)
00420                 exc.retval = -HUGE;
00421               else
00422                 exc.retval = NAN;
00423               if (_LIB_VERSION == _POSIX_)
00424                 __set_errno (EDOM);
00425               else if (!matherr(&exc)) {
00426                 if (_LIB_VERSION == _SVID_) {
00427                      (void) WRITE2("log: DOMAIN error\n", 18);
00428                     }
00429                 __set_errno (EDOM);
00430               }
00431               break;
00432            case 18:
00433            case 118:
00434            case 218:
00435               /* log10(0) */
00436               exc.type = SING;
00437               exc.name = type < 100 ? "log10" : (type < 200
00438                                              ? "log10f" : "log10l");
00439               if (_LIB_VERSION == _SVID_)
00440                 exc.retval = -HUGE;
00441               else
00442                 exc.retval = -HUGE_VAL;
00443               if (_LIB_VERSION == _POSIX_)
00444                 __set_errno (ERANGE);
00445               else if (!matherr(&exc)) {
00446                 if (_LIB_VERSION == _SVID_) {
00447                      (void) WRITE2("log10: SING error\n", 18);
00448                     }
00449                 __set_errno (EDOM);
00450               }
00451               break;
00452            case 19:
00453            case 119:
00454            case 219:
00455               /* log10(x<0) */
00456               exc.type = DOMAIN;
00457               exc.name = type < 100 ? "log10" : (type < 200
00458                                              ? "log10f" : "log10l");
00459               if (_LIB_VERSION == _SVID_)
00460                 exc.retval = -HUGE;
00461               else
00462                 exc.retval = NAN;
00463               if (_LIB_VERSION == _POSIX_)
00464                 __set_errno (EDOM);
00465               else if (!matherr(&exc)) {
00466                 if (_LIB_VERSION == _SVID_) {
00467                      (void) WRITE2("log10: DOMAIN error\n", 20);
00468                     }
00469                 __set_errno (EDOM);
00470               }
00471               break;
00472            case 20:
00473            case 120:
00474            case 220:
00475               /* pow(0.0,0.0) */
00476               /* error only if _LIB_VERSION == _SVID_ */
00477               exc.type = DOMAIN;
00478               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00479               exc.retval = zero;
00480               if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
00481               else if (!matherr(&exc)) {
00482                      (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
00483                      __set_errno (EDOM);
00484               }
00485               break;
00486            case 21:
00487            case 121:
00488            case 221:
00489               /* pow(x,y) overflow */
00490               exc.type = OVERFLOW;
00491               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00492               if (_LIB_VERSION == _SVID_) {
00493                 exc.retval = HUGE;
00494                 y *= 0.5;
00495                 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
00496               } else {
00497                 exc.retval = HUGE_VAL;
00498                 y *= 0.5;
00499                 if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
00500               }
00501               if (_LIB_VERSION == _POSIX_)
00502                 __set_errno (ERANGE);
00503               else if (!matherr(&exc)) {
00504                      __set_errno (ERANGE);
00505               }
00506               break;
00507            case 22:
00508            case 122:
00509            case 222:
00510               /* pow(x,y) underflow */
00511               exc.type = UNDERFLOW;
00512               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00513               exc.retval =  zero;
00514               if (_LIB_VERSION == _POSIX_)
00515                 __set_errno (ERANGE);
00516               else if (!matherr(&exc)) {
00517                      __set_errno (ERANGE);
00518               }
00519               break;
00520            case 23:
00521            case 123:
00522            case 223:
00523               /* -0**neg */
00524               exc.type = DOMAIN;
00525               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00526               if (_LIB_VERSION == _SVID_)
00527                 exc.retval = zero;
00528               else
00529                 exc.retval = -HUGE_VAL;
00530               if (_LIB_VERSION == _POSIX_)
00531                 __set_errno (EDOM);
00532               else if (!matherr(&exc)) {
00533                 if (_LIB_VERSION == _SVID_) {
00534                      (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
00535                     }
00536                 __set_errno (EDOM);
00537               }
00538               break;
00539            case 43:
00540            case 143:
00541            case 243:
00542               /* +0**neg */
00543               exc.type = DOMAIN;
00544               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00545               if (_LIB_VERSION == _SVID_)
00546                 exc.retval = zero;
00547               else
00548                 exc.retval = HUGE_VAL;
00549               if (_LIB_VERSION == _POSIX_)
00550                 __set_errno (EDOM);
00551               else if (!matherr(&exc)) {
00552                 if (_LIB_VERSION == _SVID_) {
00553                      (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
00554                     }
00555                 __set_errno (EDOM);
00556               }
00557               break;
00558            case 24:
00559            case 124:
00560            case 224:
00561               /* neg**non-integral */
00562               exc.type = DOMAIN;
00563               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00564               if (_LIB_VERSION == _SVID_)
00565                   exc.retval = zero;
00566               else
00567                   exc.retval = zero/zero; /* X/Open allow NaN */
00568               if (_LIB_VERSION == _POSIX_)
00569                  __set_errno (EDOM);
00570               else if (!matherr(&exc)) {
00571                 if (_LIB_VERSION == _SVID_) {
00572                      (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
00573                     }
00574                 __set_errno (EDOM);
00575               }
00576               break;
00577            case 25:
00578            case 125:
00579            case 225:
00580               /* sinh(finite) overflow */
00581               exc.type = OVERFLOW;
00582               exc.name = type < 100 ? "sinh" : (type < 200
00583                                             ? "sinhf" : "sinhl");
00584               if (_LIB_VERSION == _SVID_)
00585                 exc.retval = ( (x>zero) ? HUGE : -HUGE);
00586               else
00587                 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
00588               if (_LIB_VERSION == _POSIX_)
00589                 __set_errno (ERANGE);
00590               else if (!matherr(&exc)) {
00591                      __set_errno (ERANGE);
00592               }
00593               break;
00594            case 26:
00595            case 126:
00596            case 226:
00597               /* sqrt(x<0) */
00598               exc.type = DOMAIN;
00599               exc.name = type < 100 ? "sqrt" : (type < 200
00600                                             ? "sqrtf" : "sqrtl");
00601               if (_LIB_VERSION == _SVID_)
00602                 exc.retval = zero;
00603               else
00604                 exc.retval = zero/zero;
00605               if (_LIB_VERSION == _POSIX_)
00606                 __set_errno (EDOM);
00607               else if (!matherr(&exc)) {
00608                 if (_LIB_VERSION == _SVID_) {
00609                      (void) WRITE2("sqrt: DOMAIN error\n", 19);
00610                     }
00611                 __set_errno (EDOM);
00612               }
00613               break;
00614             case 27:
00615            case 127:
00616            case 227:
00617                 /* fmod(x,0) */
00618                 exc.type = DOMAIN;
00619                 exc.name = type < 100 ? "fmod" : (type < 200
00620                                             ? "fmodf" : "fmodl");
00621                 if (_LIB_VERSION == _SVID_)
00622                     exc.retval = x;
00623               else
00624                   exc.retval = zero/zero;
00625                 if (_LIB_VERSION == _POSIX_)
00626                   __set_errno (EDOM);
00627                 else if (!matherr(&exc)) {
00628                   if (_LIB_VERSION == _SVID_) {
00629                     (void) WRITE2("fmod:  DOMAIN error\n", 20);
00630                   }
00631                   __set_errno (EDOM);
00632                 }
00633                 break;
00634             case 28:
00635            case 128:
00636            case 228:
00637                 /* remainder(x,0) */
00638                 exc.type = DOMAIN;
00639                 exc.name = type < 100 ? "remainder" : (type < 200
00640                                                  ? "remainderf"
00641                                                  : "remainderl");
00642                 exc.retval = zero/zero;
00643                 if (_LIB_VERSION == _POSIX_)
00644                   __set_errno (EDOM);
00645                 else if (!matherr(&exc)) {
00646                   if (_LIB_VERSION == _SVID_) {
00647                     (void) WRITE2("remainder: DOMAIN error\n", 24);
00648                   }
00649                   __set_errno (EDOM);
00650                 }
00651                 break;
00652             case 29:
00653            case 129:
00654            case 229:
00655                 /* acosh(x<1) */
00656                 exc.type = DOMAIN;
00657                 exc.name = type < 100 ? "acosh" : (type < 200
00658                                              ? "acoshf" : "acoshl");
00659                 exc.retval = zero/zero;
00660                 if (_LIB_VERSION == _POSIX_)
00661                   __set_errno (EDOM);
00662                 else if (!matherr(&exc)) {
00663                   if (_LIB_VERSION == _SVID_) {
00664                     (void) WRITE2("acosh: DOMAIN error\n", 20);
00665                   }
00666                   __set_errno (EDOM);
00667                 }
00668                 break;
00669             case 30:
00670            case 130:
00671            case 230:
00672                 /* atanh(|x|>1) */
00673                 exc.type = DOMAIN;
00674                 exc.name = type < 100 ? "atanh" : (type < 200
00675                                              ? "atanhf" : "atanhl");
00676                 exc.retval = zero/zero;
00677                 if (_LIB_VERSION == _POSIX_)
00678                   __set_errno (EDOM);
00679                 else if (!matherr(&exc)) {
00680                   if (_LIB_VERSION == _SVID_) {
00681                     (void) WRITE2("atanh: DOMAIN error\n", 20);
00682                   }
00683                   __set_errno (EDOM);
00684                 }
00685                 break;
00686             case 31:
00687            case 131:
00688            case 231:
00689                 /* atanh(|x|=1) */
00690                 exc.type = SING;
00691                 exc.name = type < 100 ? "atanh" : (type < 200
00692                                              ? "atanhf" : "atanhl");
00693               exc.retval = x/zero; /* sign(x)*inf */
00694                 if (_LIB_VERSION == _POSIX_)
00695                   __set_errno (EDOM);
00696                 else if (!matherr(&exc)) {
00697                   if (_LIB_VERSION == _SVID_) {
00698                     (void) WRITE2("atanh: SING error\n", 18);
00699                   }
00700                   __set_errno (EDOM);
00701                 }
00702                 break;
00703            case 32:
00704            case 132:
00705            case 232:
00706               /* scalb overflow; SVID also returns +-HUGE_VAL */
00707               exc.type = OVERFLOW;
00708               exc.name = type < 100 ? "scalb" : (type < 200
00709                                              ? "scalbf" : "scalbl");
00710               exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
00711               if (_LIB_VERSION == _POSIX_)
00712                 __set_errno (ERANGE);
00713               else if (!matherr(&exc)) {
00714                      __set_errno (ERANGE);
00715               }
00716               break;
00717            case 33:
00718            case 133:
00719            case 233:
00720               /* scalb underflow */
00721               exc.type = UNDERFLOW;
00722               exc.name = type < 100 ? "scalb" : (type < 200
00723                                              ? "scalbf" : "scalbl");
00724               exc.retval = __copysign(zero,x);
00725               if (_LIB_VERSION == _POSIX_)
00726                 __set_errno (ERANGE);
00727               else if (!matherr(&exc)) {
00728                      __set_errno (ERANGE);
00729               }
00730               break;
00731            case 34:
00732            case 134:
00733            case 234:
00734               /* j0(|x|>X_TLOSS) */
00735                 exc.type = TLOSS;
00736                 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
00737                 exc.retval = zero;
00738                 if (_LIB_VERSION == _POSIX_)
00739                         __set_errno (ERANGE);
00740                 else if (!matherr(&exc)) {
00741                         if (_LIB_VERSION == _SVID_) {
00742                                 (void) WRITE2(exc.name, 2);
00743                                 (void) WRITE2(": TLOSS error\n", 14);
00744                         }
00745                         __set_errno (ERANGE);
00746                 }
00747               break;
00748            case 35:
00749            case 135:
00750            case 235:
00751               /* y0(x>X_TLOSS) */
00752                 exc.type = TLOSS;
00753                 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
00754                 exc.retval = zero;
00755                 if (_LIB_VERSION == _POSIX_)
00756                         __set_errno (ERANGE);
00757                 else if (!matherr(&exc)) {
00758                         if (_LIB_VERSION == _SVID_) {
00759                                 (void) WRITE2(exc.name, 2);
00760                                 (void) WRITE2(": TLOSS error\n", 14);
00761                         }
00762                         __set_errno (ERANGE);
00763                 }
00764               break;
00765            case 36:
00766            case 136:
00767            case 236:
00768               /* j1(|x|>X_TLOSS) */
00769                 exc.type = TLOSS;
00770                 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
00771                 exc.retval = zero;
00772                 if (_LIB_VERSION == _POSIX_)
00773                         __set_errno (ERANGE);
00774                 else if (!matherr(&exc)) {
00775                         if (_LIB_VERSION == _SVID_) {
00776                                 (void) WRITE2(exc.name, 2);
00777                                 (void) WRITE2(": TLOSS error\n", 14);
00778                         }
00779                         __set_errno (ERANGE);
00780                 }
00781               break;
00782            case 37:
00783            case 137:
00784            case 237:
00785               /* y1(x>X_TLOSS) */
00786                 exc.type = TLOSS;
00787                 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
00788                 exc.retval = zero;
00789                 if (_LIB_VERSION == _POSIX_)
00790                         __set_errno (ERANGE);
00791                 else if (!matherr(&exc)) {
00792                         if (_LIB_VERSION == _SVID_) {
00793                                 (void) WRITE2(exc.name, 2);
00794                                 (void) WRITE2(": TLOSS error\n", 14);
00795                         }
00796                         __set_errno (ERANGE);
00797                 }
00798               break;
00799            case 38:
00800            case 138:
00801            case 238:
00802               /* jn(|x|>X_TLOSS) */
00803                 exc.type = TLOSS;
00804                 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
00805                 exc.retval = zero;
00806                 if (_LIB_VERSION == _POSIX_)
00807                         __set_errno (ERANGE);
00808                 else if (!matherr(&exc)) {
00809                         if (_LIB_VERSION == _SVID_) {
00810                                 (void) WRITE2(exc.name, 2);
00811                                 (void) WRITE2(": TLOSS error\n", 14);
00812                         }
00813                         __set_errno (ERANGE);
00814                 }
00815               break;
00816            case 39:
00817            case 139:
00818            case 239:
00819               /* yn(x>X_TLOSS) */
00820                 exc.type = TLOSS;
00821                 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
00822                 exc.retval = zero;
00823                 if (_LIB_VERSION == _POSIX_)
00824                         __set_errno (ERANGE);
00825                 else if (!matherr(&exc)) {
00826                         if (_LIB_VERSION == _SVID_) {
00827                                 (void) WRITE2(exc.name, 2);
00828                                 (void) WRITE2(": TLOSS error\n", 14);
00829                         }
00830                         __set_errno (ERANGE);
00831                 }
00832               break;
00833            case 40:
00834            case 140:
00835            case 240:
00836               /* tgamma(finite) overflow */
00837               exc.type = OVERFLOW;
00838               exc.name = type < 100 ? "tgamma" : (type < 200
00839                                              ? "tgammaf" : "tgammal");
00840               exc.retval = HUGE_VAL;
00841                 if (_LIB_VERSION == _POSIX_)
00842                 __set_errno (ERANGE);
00843                 else if (!matherr(&exc)) {
00844                   __set_errno (ERANGE);
00845                 }
00846               break;
00847            case 41:
00848            case 141:
00849            case 241:
00850               /* tgamma(-integer) */
00851               exc.type = SING;
00852               exc.name = type < 100 ? "tgamma" : (type < 200
00853                                              ? "tgammaf" : "tgammal");
00854               exc.retval = NAN;
00855               if (_LIB_VERSION == _POSIX_)
00856                 __set_errno (EDOM);
00857               else if (!matherr(&exc)) {
00858                 if (_LIB_VERSION == _SVID_) {
00859                      (void) WRITE2("tgamma: SING error\n", 18);
00860                      exc.retval = HUGE_VAL;
00861                     }
00862                 __set_errno (EDOM);
00863               }
00864               break;
00865            case 42:
00866            case 142:
00867            case 242:
00868               /* pow(NaN,0.0) */
00869               /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
00870               exc.type = DOMAIN;
00871               exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
00872               exc.retval = x;
00873               if (_LIB_VERSION == _IEEE_ ||
00874                   _LIB_VERSION == _POSIX_) exc.retval = 1.0;
00875               else if (!matherr(&exc)) {
00876                      __set_errno (EDOM);
00877               }
00878               break;
00879 
00880            case 44:
00881            case 144:
00882            case 244:
00883               /* exp(finite) overflow */
00884               exc.type = OVERFLOW;
00885               exc.name = type < 100 ? "exp2" : (type < 200
00886                                             ? "exp2f" : "exp2l");
00887               if (_LIB_VERSION == _SVID_)
00888                 exc.retval = HUGE;
00889               else
00890                 exc.retval = HUGE_VAL;
00891               if (_LIB_VERSION == _POSIX_)
00892                 __set_errno (ERANGE);
00893               else if (!matherr(&exc)) {
00894                      __set_errno (ERANGE);
00895               }
00896               break;
00897            case 45:
00898            case 145:
00899            case 245:
00900               /* exp(finite) underflow */
00901               exc.type = UNDERFLOW;
00902               exc.name = type < 100 ? "exp2" : (type < 200
00903                                             ? "exp2f" : "exp2l");
00904               exc.retval = zero;
00905               if (_LIB_VERSION == _POSIX_)
00906                 __set_errno (ERANGE);
00907               else if (!matherr(&exc)) {
00908                      __set_errno (ERANGE);
00909               }
00910               break;
00911 
00912            case 46:
00913            case 146:
00914            case 246:
00915               /* exp(finite) overflow */
00916               exc.type = OVERFLOW;
00917               exc.name = type < 100 ? "exp10" : (type < 200
00918                                              ? "exp10f" : "exp10l");
00919               if (_LIB_VERSION == _SVID_)
00920                 exc.retval = HUGE;
00921               else
00922                 exc.retval = HUGE_VAL;
00923               if (_LIB_VERSION == _POSIX_)
00924                 __set_errno (ERANGE);
00925               else if (!matherr(&exc)) {
00926                      __set_errno (ERANGE);
00927               }
00928               break;
00929            case 47:
00930            case 147:
00931            case 247:
00932               /* exp(finite) underflow */
00933               exc.type = UNDERFLOW;
00934               exc.name = type < 100 ? "exp10" : (type < 200
00935                                              ? "exp10f" : "exp10l");
00936               exc.retval = zero;
00937               if (_LIB_VERSION == _POSIX_)
00938                 __set_errno (ERANGE);
00939               else if (!matherr(&exc)) {
00940                      __set_errno (ERANGE);
00941               }
00942               break;
00943            case 48:
00944            case 148:
00945            case 248:
00946               /* log2(0) */
00947               exc.type = SING;
00948               exc.name = type < 100 ? "log2" : (type < 200
00949                                              ? "log2f" : "log2l");
00950               if (_LIB_VERSION == _SVID_)
00951                 exc.retval = -HUGE;
00952               else
00953                 exc.retval = -HUGE_VAL;
00954               if (_LIB_VERSION == _POSIX_)
00955                 __set_errno (ERANGE);
00956               else if (!matherr(&exc)) {
00957                 __set_errno (EDOM);
00958               }
00959               break;
00960            case 49:
00961            case 149:
00962            case 249:
00963               /* log2(x<0) */
00964               exc.type = DOMAIN;
00965               exc.name = type < 100 ? "log2" : (type < 200
00966                                              ? "log2f" : "log2l");
00967               if (_LIB_VERSION == _SVID_)
00968                 exc.retval = -HUGE;
00969               else
00970                 exc.retval = NAN;
00971               if (_LIB_VERSION == _POSIX_)
00972                 __set_errno (EDOM);
00973               else if (!matherr(&exc)) {
00974                 __set_errno (EDOM);
00975               }
00976               break;
00977            case 50:
00978            case 150:
00979            case 250:
00980               /* tgamma(+-0) */
00981               exc.type = SING;
00982               exc.name = type < 100 ? "tgamma" : (type < 200
00983                                               ? "tgammaf" : "tgammal");
00984               exc.retval = __copysign (HUGE_VAL, x);
00985               if (_LIB_VERSION == _POSIX_)
00986                 __set_errno (ERANGE);
00987               else if (!matherr(&exc)) {
00988                 if (_LIB_VERSION == _SVID_)
00989                   (void) WRITE2("tgamma: SING error\n", 18);
00990                 __set_errno (ERANGE);
00991               }
00992               break;
00993               
00994               /* #### Last used is 50/150/250 ### */
00995        }
00996        return exc.retval;
00997 }