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

  1. /* _Sinh 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 double p[] = {    /* courtesy Dr. Tim Prince */
  9.     0.0000000001632881,
  10.     0.0000000250483893,
  11.     0.0000027557344615,
  12.     0.0001984126975233,
  13.     0.0083333333334816,
  14.     0.1666666666666574,
  15.     1.0000000000000001};
  16.  
  17. _CRTIMP2 double __cdecl _Sinh(double x, double y)
  18.     {    /* compute y*sinh(x), |y| <= 1 */
  19.     switch (_Dtest(&x))
  20.         {    /* test for special codes */
  21.     case NAN:
  22.         errno = EDOM;
  23.         return (x);
  24.     case INF:
  25.         if (y == 0)
  26.             return (0);
  27.         errno = ERANGE;
  28.         return (DSIGN(x) ? -_Inf._D : _Inf._D);
  29.     case 0:
  30.         return (0);
  31.     default:    /* finite */
  32.          {    /* compute sinh(finite) */
  33.         short neg;
  34.  
  35.         if (x < 0)
  36.             x = -x, neg = 1;
  37.         else
  38.             neg = 0;
  39.         if (x < _Rteps._D)
  40.             x *= y;    /* x tiny */
  41.         else if (x < 1)
  42.             {
  43.             double w = x * x;
  44.  
  45.             x += x * w * _Poly(w, p, NP - 1);
  46.             x *= y;
  47.             }
  48.         else if (x < _Xbig)
  49.             {    /* worth adding in exp(-x) */
  50.             _Exp(&x, 1, -1);
  51.             x = y * (x - 0.25 / x);
  52.             }
  53.         else if (0 <= _Exp(&x, y, -1))
  54.             errno = ERANGE;    /* x large */
  55.         return (neg ? -x : x);
  56.          }
  57.         }
  58.     }
  59. _STD_END
  60.  
  61. /*
  62.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  63.  * Consult your license regarding permissions and restrictions.
  64.  */
  65.  
  66. /*
  67. 941029 pjp: added _STD machinery
  68.  */
  69.