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

  1. /* _LSinh 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 long double p[] = {    /* courtesy Dr. Tim Prince */
  9.     0.0000000000000028486835L,
  10.     0.0000000000007646464279L,
  11.     0.0000000001605905091647L,
  12.     0.0000000250521083436962L,
  13.     0.0000027557319224130455L,
  14.     0.0001984126984126956009L,
  15.     0.0083333333333333336073L,
  16.     0.1666666666666666666564L,
  17.     1.0000000000000000000001L};
  18.  
  19. _CRTIMP2 long double __cdecl _LSinh(long double x, long double y)
  20.     {    /* compute y*sinh(x), |y| <= 1 */
  21.     switch (_LDtest(&x))
  22.         {    /* test for special codes */
  23.     case NAN:
  24.         errno = EDOM;
  25.         return (x);
  26.     case INF:
  27.         if (y == 0)
  28.             return (0);
  29.         errno = ERANGE;
  30.         return (LSIGN(x) ? -_LInf._L : _LInf._L);
  31.     case 0:
  32.         return (0);
  33.     default:    /* finite */
  34.          {    /* compute sinh(finite) */
  35.         short neg;
  36.  
  37.         if (x < 0)
  38.             x = -x, neg = 1;
  39.         else
  40.             neg = 0;
  41.         if (x < _LRteps._L)
  42.             x *= y;    /* x tiny */
  43.         else if (x < 1)
  44.             {
  45.             long double w = x * x;
  46.  
  47.             x += x * w * _LPoly(w, p, NP - 1);
  48.             x *= y;
  49.             }
  50.         else if (x < _LXbig)
  51.             {    /* worth adding in exp(-x) */
  52.             _LExp(&x, 1, -1);
  53.             x = y * (x - 0.25 / x);
  54.             }
  55.         else if (0 <= _LExp(&x, y, -1))
  56.             errno = ERANGE;    /* x large */
  57.         return (neg ? -x : x);
  58.          }
  59.         }
  60.     }
  61. _STD_END
  62.  
  63. /*
  64.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  65.  * Consult your license regarding permissions and restrictions.
  66.  */
  67.  
  68. /*
  69. 941029 pjp: added _STD machinery
  70.  */
  71.