e_sinh.c revision 2116
10Sstevel@tonic-gate/* @(#)e_sinh.c 5.1 93/09/24 */
20Sstevel@tonic-gate/*
30Sstevel@tonic-gate * ====================================================
40Sstevel@tonic-gate * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
50Sstevel@tonic-gate *
60Sstevel@tonic-gate * Developed at SunPro, a Sun Microsystems, Inc. business.
70Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this
80Sstevel@tonic-gate * software is freely granted, provided that this notice
90Sstevel@tonic-gate * is preserved.
100Sstevel@tonic-gate * ====================================================
110Sstevel@tonic-gate */
120Sstevel@tonic-gate
130Sstevel@tonic-gate#ifndef lint
140Sstevel@tonic-gatestatic char rcsid[] = "$Id: e_sinh.c,v 1.5 1994/08/18 23:06:03 jtc Exp $";
150Sstevel@tonic-gate#endif
160Sstevel@tonic-gate
170Sstevel@tonic-gate/* __ieee754_sinh(x)
180Sstevel@tonic-gate * Method :
190Sstevel@tonic-gate * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
200Sstevel@tonic-gate *	1. Replace x by |x| (sinh(-x) = -sinh(x)).
210Sstevel@tonic-gate *	2.
220Sstevel@tonic-gate *		                                    E + E/(E+1)
230Sstevel@tonic-gate *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
240Sstevel@tonic-gate *			       			        2
250Sstevel@tonic-gate *
260Sstevel@tonic-gate *	    22       <= x <= lnovft :  sinh(x) := exp(x)/2
270Sstevel@tonic-gate *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
280Sstevel@tonic-gate *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * Special cases:
310Sstevel@tonic-gate *	sinh(x) is |x| if x is +INF, -INF, or NaN.
320Sstevel@tonic-gate *	only sinh(0)=0 is exact for finite x.
330Sstevel@tonic-gate */
340Sstevel@tonic-gate
350Sstevel@tonic-gate#include "math.h"
360Sstevel@tonic-gate#include "math_private.h"
370Sstevel@tonic-gate
380Sstevel@tonic-gate#ifdef __STDC__
390Sstevel@tonic-gatestatic const double one = 1.0, shuge = 1.0e307;
400Sstevel@tonic-gate#else
410Sstevel@tonic-gatestatic double one = 1.0, shuge = 1.0e307;
420Sstevel@tonic-gate#endif
43
44#ifdef __STDC__
45	double __ieee754_sinh(double x)
46#else
47	double __ieee754_sinh(x)
48	double x;
49#endif
50{
51	double t,w,h;
52	int32_t ix,jx;
53	u_int32_t lx;
54
55    /* High word of |x|. */
56	GET_HIGH_WORD(jx,x);
57	ix = jx&0x7fffffff;
58
59    /* x is INF or NaN */
60	if(ix>=0x7ff00000) return x+x;
61
62	h = 0.5;
63	if (jx<0) h = -h;
64    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
65	if (ix < 0x40360000) {		/* |x|<22 */
66	    if (ix<0x3e300000) 		/* |x|<2**-28 */
67		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
68	    t = expm1(fabs(x));
69	    if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
70	    return h*(t+t/(t+one));
71	}
72
73    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
74	if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
75
76    /* |x| in [log(maxdouble), overflowthresold] */
77	GET_LOW_WORD(lx,x);
78	if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d)) {
79	    w = __ieee754_exp(0.5*fabs(x));
80	    t = h*w;
81	    return t*w;
82	}
83
84    /* |x| > overflowthresold, sinh(x) overflow */
85	return x*shuge;
86}
87