Subversion Repositories Kolibri OS

Rev

Rev 4973 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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