e_sinh.c revision 141296
11590Srgrimes 259945Sphantom/* @(#)e_sinh.c 1.3 95/01/18 */ 31590Srgrimes/* 41590Srgrimes * ==================================================== 515714Sache * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 695688Sdwmalone * 795753Sdwmalone * Developed at SunSoft, a Sun Microsystems, Inc. business. 878046Sache * Permission to use, copy, modify, and distribute this 978046Sache * software is freely granted, provided that this notice 1013684Swosch * is preserved. 111590Srgrimes * ==================================================== 121590Srgrimes */ 1313684Swosch 1415008Sjdp#ifndef lint 1514147Swoschstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/e_sinh.c 141296 2005-02-04 18:26:06Z das $"; 1614147Swosch#endif 1786053Sdd 1815008Sjdp/* __ieee754_sinh(x) 1914147Swosch * Method : 2078046Sache * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 2178046Sache * 1. Replace x by |x| (sinh(-x) = -sinh(x)). 2278046Sache * 2. 2378046Sache * E + E/(E+1) 2478046Sache * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) 2578046Sache * 2 2678046Sache * 2778046Sache * 22 <= x <= lnovft : sinh(x) := exp(x)/2 281590Srgrimes * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) 291590Srgrimes * ln2ovft < x : sinh(x) := x*shuge (overflow) 30 * 31 * Special cases: 32 * sinh(x) is |x| if x is +INF, -INF, or NaN. 33 * only sinh(0)=0 is exact for finite x. 34 */ 35 36#include "math.h" 37#include "math_private.h" 38 39static const double one = 1.0, shuge = 1.0e307; 40 41double 42__ieee754_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*__ieee754_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 = __ieee754_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