gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/math/e_sinh.cbare sourcepermlink (0.02 seconds)

Search this content:

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