home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / xfsinh.c < prev    next >
C/C++ Source or Header  |  1998-06-16  |  1KB  |  66 lines

  1. /* _FSinh function */
  2. #include "wctype.h"
  3. #include "xmath.h"
  4. _STD_BEGIN
  5.  
  6. /* coefficients */
  7. #define NP    (sizeof (p) / sizeof (p[0]) - 1)
  8. static const float p[] = {    /* courtesy Dr. Tim Prince */
  9.     0.00020400F,
  10.     0.00832983F,
  11.     0.16666737F,
  12.     0.99999998F};
  13.  
  14. _CRTIMP2 float __cdecl _FSinh(float x, float y)
  15.     {    /* compute y*sinh(x), |y| <= 1 */
  16.     switch (_FDtest(&x))
  17.         {    /* test for special codes */
  18.     case NAN:
  19.         errno = EDOM;
  20.         return (x);
  21.     case INF:
  22.         if (y == 0)
  23.             return (0);
  24.         errno = ERANGE;
  25.         return (FSIGN(x) ? -_FInf._F : _FInf._F);
  26.     case 0:
  27.         return (0);
  28.     default:    /* finite */
  29.          {    /* compute sinh(finite) */
  30.         short neg;
  31.  
  32.         if (x < 0)
  33.             x = -x, neg = 1;
  34.         else
  35.             neg = 0;
  36.         if (x < _FRteps._F)
  37.             x *= y;    /* x tiny */
  38.         else if (x < 1)
  39.             {
  40.             float w = x * x;
  41.  
  42.             x += ((p[0] * w + p[1]) * w + p[2]) * w * x;
  43.             x *= y;
  44.             }
  45.         else if (x < _FXbig)
  46.             {    /* worth adding in exp(-x) */
  47.             _FExp(&x, 1, -1);
  48.             x = y * (x - 0.25 / x);
  49.             }
  50.         else if (0 <= _FExp(&x, y, -1))
  51.             errno = ERANGE;    /* x large */
  52.         return (neg ? -x : x);
  53.          }
  54.         }
  55.     }
  56. _STD_END
  57.  
  58. /*
  59.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  60.  * Consult your license regarding permissions and restrictions.
  61.  */
  62.  
  63. /*
  64. 941029 pjp: added _STD machinery
  65.  */
  66.