1 /* derived from /netlib/fdlibm */ 2 3 /* @(#)e_sinh.c 1.3 95/01/18 */ 4 /* 5 * ==================================================== 6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7 * 8 * Developed at SunSoft, 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 /* __ieee754_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 "fdlibm.h" 34 35 static const double one = 1.0, sHuge = 1.0e307; 36 __ieee754_sinh(double x)37 double __ieee754_sinh(double x) 38 { 39 double t,w,h; 40 int ix,jx; 41 unsigned lx; 42 43 /* High word of |x|. */ 44 jx = __HI(x); 45 ix = jx&0x7fffffff; 46 47 /* x is INF or NaN */ 48 if(ix>=0x7ff00000) return x+x; 49 50 h = 0.5; 51 if (jx<0) h = -h; 52 /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ 53 if (ix < 0x40360000) { /* |x|<22 */ 54 if (ix<0x3e300000) /* |x|<2**-28 */ 55 if(sHuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ 56 t = expm1(fabs(x)); 57 if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); 58 return h*(t+t/(t+one)); 59 } 60 61 /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ 62 if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); 63 64 /* |x| in [log(maxdouble), overflowthresold] */ 65 lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x); 66 if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) { 67 w = __ieee754_exp(0.5*fabs(x)); 68 t = h*w; 69 return t*w; 70 } 71 72 /* |x| > overflowthresold, sinh(x) overflow */ 73 return x*sHuge; 74 } 75