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