e_sinh.c revision 8870
12116Sjkh/* @(#)e_sinh.c 5.1 93/09/24 */
22116Sjkh/*
32116Sjkh * ====================================================
42116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
52116Sjkh *
62116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business.
72116Sjkh * Permission to use, copy, modify, and distribute this
88870Srgrimes * software is freely granted, provided that this notice
92116Sjkh * is preserved.
102116Sjkh * ====================================================
112116Sjkh */
122116Sjkh
132116Sjkh#ifndef lint
148870Srgrimesstatic char rcsid[] = "$Id: e_sinh.c,v 1.1.1.1 1994/08/19 09:39:44 jkh Exp $";
152116Sjkh#endif
162116Sjkh
172116Sjkh/* __ieee754_sinh(x)
188870Srgrimes * Method :
192116Sjkh * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
208870Srgrimes *	1. Replace x by |x| (sinh(-x) = -sinh(x)).
218870Srgrimes *	2.
222116Sjkh *		                                    E + E/(E+1)
232116Sjkh *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
242116Sjkh *			       			        2
252116Sjkh *
268870Srgrimes *	    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
382116Sjkh#ifdef __STDC__
392116Sjkhstatic const double one = 1.0, shuge = 1.0e307;
402116Sjkh#else
412116Sjkhstatic double one = 1.0, shuge = 1.0e307;
422116Sjkh#endif
432116Sjkh
442116Sjkh#ifdef __STDC__
452116Sjkh	double __ieee754_sinh(double x)
462116Sjkh#else
472116Sjkh	double __ieee754_sinh(x)
482116Sjkh	double x;
492116Sjkh#endif
508870Srgrimes{
512116Sjkh	double t,w,h;
522116Sjkh	int32_t ix,jx;
532116Sjkh	u_int32_t lx;
542116Sjkh
552116Sjkh    /* High word of |x|. */
562116Sjkh	GET_HIGH_WORD(jx,x);
572116Sjkh	ix = jx&0x7fffffff;
582116Sjkh
592116Sjkh    /* x is INF or NaN */
608870Srgrimes	if(ix>=0x7ff00000) return x+x;
612116Sjkh
622116Sjkh	h = 0.5;
632116Sjkh	if (jx<0) h = -h;
642116Sjkh    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
652116Sjkh	if (ix < 0x40360000) {		/* |x|<22 */
662116Sjkh	    if (ix<0x3e300000) 		/* |x|<2**-28 */
672116Sjkh		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
682116Sjkh	    t = expm1(fabs(x));
692116Sjkh	    if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
702116Sjkh	    return h*(t+t/(t+one));
712116Sjkh	}
722116Sjkh
732116Sjkh    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
742116Sjkh	if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
752116Sjkh
762116Sjkh    /* |x| in [log(maxdouble), overflowthresold] */
772116Sjkh	GET_LOW_WORD(lx,x);
782116Sjkh	if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d)) {
792116Sjkh	    w = __ieee754_exp(0.5*fabs(x));
802116Sjkh	    t = h*w;
812116Sjkh	    return t*w;
822116Sjkh	}
832116Sjkh
842116Sjkh    /* |x| > overflowthresold, sinh(x) overflow */
852116Sjkh	return x*shuge;
862116Sjkh}
87