home *** CD-ROM | disk | FTP | other *** search
/ Game Zone - 1,000+ Games / GAMEZONE.BIN / Programs / PALM / Oh-One / src / e_sinh.c < prev    next >
C/C++ Source or Header  |  1997-08-16  |  2KB  |  89 lines

  1. // 15 August 1997, Rick Huebner:  Small changes made to adapt for MathLib
  2.  
  3. /* @(#)e_sinh.c 5.1 93/09/24 */
  4. /*
  5.  * ====================================================
  6.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7.  *
  8.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software is freely granted, provided that this notice 
  11.  * is preserved.
  12.  * ====================================================
  13.  */
  14.  
  15. #if defined(LIBM_SCCS) && !defined(lint)
  16. static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
  17. #endif
  18.  
  19. /* __ieee754_sinh(x)
  20.  * Method : 
  21.  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  22.  *    1. Replace x by |x| (sinh(-x) = -sinh(x)). 
  23.  *    2. 
  24.  *                                            E + E/(E+1)
  25.  *        0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
  26.  *                                       2
  27.  *
  28.  *        22       <= x <= lnovft :  sinh(x) := exp(x)/2 
  29.  *        lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
  30.  *        ln2ovft  <  x        :  sinh(x) := x*shuge (overflow)
  31.  *
  32.  * Special cases:
  33.  *    sinh(x) is |x| if x is +INF, -INF, or NaN.
  34.  *    only sinh(0)=0 is exact for finite x.
  35.  */
  36.  
  37. #include "math.h"
  38. #include "math_private.h"
  39.  
  40. #ifdef __STDC__
  41. static const double one = 1.0, shuge = 1.0e307;
  42. #else
  43. static double one = 1.0, shuge = 1.0e307;
  44. #endif
  45.  
  46. #ifdef __STDC__
  47.     double __ieee754_sinh(double x)
  48. #else
  49.     double __ieee754_sinh(x)
  50.     double x;
  51. #endif
  52. {    
  53.     double t,w,h;
  54.     int32_t ix,jx;
  55.     u_int32_t lx;
  56.  
  57.     /* High word of |x|. */
  58.     GET_HIGH_WORD(jx,x);
  59.     ix = jx&0x7fffffff;
  60.  
  61.     /* x is INF or NaN */
  62.     if(ix>=0x7ff00000) return x+x;    
  63.  
  64.     h = 0.5;
  65.     if (jx<0) h = -h;
  66.     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
  67.     if (ix < 0x40360000) {        /* |x|<22 */
  68.         if (ix<0x3e300000)         /* |x|<2**-28 */
  69.         if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
  70.         t = __expm1(__fabs(x));
  71.         if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
  72.         return h*(t+t/(t+one));
  73.     }
  74.  
  75.     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
  76.     if (ix < 0x40862E42)  return h*__ieee754_exp(__fabs(x));
  77.  
  78.     /* |x| in [log(maxdouble), overflowthresold] */
  79.     GET_LOW_WORD(lx,x);
  80.     if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d)) {
  81.         w = __ieee754_exp(0.5*__fabs(x));
  82.         t = h*w;
  83.         return t*w;
  84.     }
  85.  
  86.     /* |x| > overflowthresold, sinh(x) overflow */
  87.     return x*shuge;
  88. }
  89.