e_sinh.c revision 141296
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 142116Sjkh#ifndef lint 1550476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/e_sinh.c 141296 2005-02-04 18:26:06Z das $"; 162116Sjkh#endif 172116Sjkh 182116Sjkh/* __ieee754_sinh(x) 19141296Sdas * Method : 202116Sjkh * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 21141296Sdas * 1. Replace x by |x| (sinh(-x) = -sinh(x)). 22141296Sdas * 2. 232116Sjkh * E + E/(E+1) 242116Sjkh * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) 252116Sjkh * 2 262116Sjkh * 27141296Sdas * 22 <= x <= lnovft : sinh(x) := exp(x)/2 282116Sjkh * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) 292116Sjkh * ln2ovft < x : sinh(x) := x*shuge (overflow) 302116Sjkh * 312116Sjkh * Special cases: 322116Sjkh * sinh(x) is |x| if x is +INF, -INF, or NaN. 332116Sjkh * only sinh(0)=0 is exact for finite x. 342116Sjkh */ 352116Sjkh 362116Sjkh#include "math.h" 372116Sjkh#include "math_private.h" 382116Sjkh 392116Sjkhstatic const double one = 1.0, shuge = 1.0e307; 402116Sjkh 4197413Salfreddouble 4297413Salfred__ieee754_sinh(double x) 438870Srgrimes{ 442116Sjkh double t,w,h; 452116Sjkh int32_t ix,jx; 462116Sjkh u_int32_t lx; 472116Sjkh 482116Sjkh /* High word of |x|. */ 492116Sjkh GET_HIGH_WORD(jx,x); 502116Sjkh ix = jx&0x7fffffff; 512116Sjkh 522116Sjkh /* x is INF or NaN */ 53141296Sdas if(ix>=0x7ff00000) return x+x; 542116Sjkh 552116Sjkh h = 0.5; 562116Sjkh if (jx<0) h = -h; 572116Sjkh /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ 582116Sjkh if (ix < 0x40360000) { /* |x|<22 */ 592116Sjkh if (ix<0x3e300000) /* |x|<2**-28 */ 602116Sjkh if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ 612116Sjkh t = expm1(fabs(x)); 622116Sjkh if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); 632116Sjkh return h*(t+t/(t+one)); 642116Sjkh } 652116Sjkh 662116Sjkh /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ 672116Sjkh if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); 682116Sjkh 692116Sjkh /* |x| in [log(maxdouble), overflowthresold] */ 702116Sjkh GET_LOW_WORD(lx,x); 7117141Sjkh if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) { 722116Sjkh w = __ieee754_exp(0.5*fabs(x)); 732116Sjkh t = h*w; 742116Sjkh return t*w; 752116Sjkh } 762116Sjkh 772116Sjkh /* |x| > overflowthresold, sinh(x) overflow */ 782116Sjkh return x*shuge; 792116Sjkh} 80