e_sinh.c revision 176451
1141296Sdas 2141296Sdas/* @(#)e_sinh.c 1.3 95/01/18 */ 32116Sjkh/* 42116Sjkh * ==================================================== 52116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 62116Sjkh * 7141296Sdas * Developed at SunSoft, a Sun Microsystems, Inc. business. 82116Sjkh * Permission to use, copy, modify, and distribute this 9141296Sdas * software is freely granted, provided that this notice 102116Sjkh * is preserved. 112116Sjkh * ==================================================== 122116Sjkh */ 132116Sjkh 14176451Sdas#include <sys/cdefs.h> 15176451Sdas__FBSDID("$FreeBSD: head/lib/msun/src/e_sinh.c 176451 2008-02-22 02:30:36Z das $"); 162116Sjkh 172116Sjkh/* __ieee754_sinh(x) 18141296Sdas * Method : 192116Sjkh * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 20141296Sdas * 1. Replace x by |x| (sinh(-x) = -sinh(x)). 21141296Sdas * 2. 222116Sjkh * E + E/(E+1) 232116Sjkh * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) 242116Sjkh * 2 252116Sjkh * 26141296Sdas * 22 <= x <= lnovft : sinh(x) := exp(x)/2 272116Sjkh * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) 282116Sjkh * ln2ovft < x : sinh(x) := x*shuge (overflow) 292116Sjkh * 302116Sjkh * Special cases: 312116Sjkh * sinh(x) is |x| if x is +INF, -INF, or NaN. 322116Sjkh * only sinh(0)=0 is exact for finite x. 332116Sjkh */ 342116Sjkh 352116Sjkh#include "math.h" 362116Sjkh#include "math_private.h" 372116Sjkh 382116Sjkhstatic const double one = 1.0, shuge = 1.0e307; 392116Sjkh 4097413Salfreddouble 4197413Salfred__ieee754_sinh(double x) 428870Srgrimes{ 432116Sjkh double t,w,h; 442116Sjkh int32_t ix,jx; 452116Sjkh u_int32_t lx; 462116Sjkh 472116Sjkh /* High word of |x|. */ 482116Sjkh GET_HIGH_WORD(jx,x); 492116Sjkh ix = jx&0x7fffffff; 502116Sjkh 512116Sjkh /* x is INF or NaN */ 52141296Sdas if(ix>=0x7ff00000) return x+x; 532116Sjkh 542116Sjkh h = 0.5; 552116Sjkh if (jx<0) h = -h; 562116Sjkh /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ 572116Sjkh if (ix < 0x40360000) { /* |x|<22 */ 582116Sjkh if (ix<0x3e300000) /* |x|<2**-28 */ 592116Sjkh if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ 602116Sjkh t = expm1(fabs(x)); 612116Sjkh if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); 622116Sjkh return h*(t+t/(t+one)); 632116Sjkh } 642116Sjkh 652116Sjkh /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ 662116Sjkh if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); 672116Sjkh 682116Sjkh /* |x| in [log(maxdouble), overflowthresold] */ 692116Sjkh GET_LOW_WORD(lx,x); 7017141Sjkh if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) { 712116Sjkh w = __ieee754_exp(0.5*fabs(x)); 722116Sjkh t = h*w; 732116Sjkh return t*w; 742116Sjkh } 752116Sjkh 762116Sjkh /* |x| > overflowthresold, sinh(x) overflow */ 772116Sjkh return x*shuge; 782116Sjkh} 79