e_sinh.c revision 260067
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 260067 2013-12-30 01:06:21Z kargl $"); 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 35260067Skargl#include <float.h> 36260067Skargl 372116Sjkh#include "math.h" 382116Sjkh#include "math_private.h" 392116Sjkh 402116Sjkhstatic const double one = 1.0, shuge = 1.0e307; 412116Sjkh 4297413Salfreddouble 4397413Salfred__ieee754_sinh(double x) 448870Srgrimes{ 45226598Sdas double t,h; 462116Sjkh int32_t ix,jx; 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] */ 70226598Sdas if (ix<=0x408633CE) 71226598Sdas return h*2.0*__ldexp_exp(fabs(x), -1); 722116Sjkh 732116Sjkh /* |x| > overflowthresold, sinh(x) overflow */ 742116Sjkh return x*shuge; 752116Sjkh} 76260067Skargl 77260067Skargl#if (LDBL_MANT_DIG == 53) 78260067Skargl__weak_reference(sinh, sinhl); 79260067Skargl#endif 80