Numworks Epsilon  1.4.1
Graphing Calculator Operating System
e_sinh.c
Go to the documentation of this file.
1 /* @(#)e_sinh.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 /* sinh(x)
14  * Method :
15  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
16  * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
17  * 2.
18  * E + E/(E+1)
19  * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
20  * 2
21  *
22  * 22 <= x <= lnovft : sinh(x) := exp(x)/2
23  * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
24  * ln2ovft < x : sinh(x) := x*shuge (overflow)
25  *
26  * Special cases:
27  * sinh(x) is |x| if x is +INF, -INF, or NaN.
28  * only sinh(0)=0 is exact for finite x.
29  */
30 
31 #include "math.h"
32 #include "math_private.h"
33 
34 static const double one = 1.0, shuge = 1.0e307;
35 
36 double
37 sinh(double x)
38 {
39  double t,w,h;
40  int32_t ix,jx;
41  u_int32_t lx;
42 
43  /* High word of |x|. */
44  GET_HIGH_WORD(jx,x);
45  ix = jx&0x7fffffff;
46 
47  /* x is INF or NaN */
48  if(ix>=0x7ff00000) return x+x;
49 
50  h = 0.5;
51  if (jx<0) h = -h;
52  /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
53  if (ix < 0x40360000) { /* |x|<22 */
54  if (ix<0x3e300000) /* |x|<2**-28 */
55  if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
56  t = expm1(fabs(x));
57  if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
58  return h*(t+t/(t+one));
59  }
60 
61  /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
62  if (ix < 0x40862E42) return h*exp(fabs(x));
63 
64  /* |x| in [log(maxdouble), overflowthresold] */
65  GET_LOW_WORD(lx,x);
66  if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
67  w = exp(0.5*fabs(x));
68  t = h*w;
69  return t*w;
70  }
71 
72  /* |x| > overflowthresold, sinh(x) overflow */
73  return x*shuge;
74 }
#define GET_HIGH_WORD(i, d)
Definition: math_private.h:269
#define exp(x)
Definition: math.h:176
#define one
Definition: k_tan.c:68
uint32_t u_int32_t
Definition: types.h:10
#define fabs(x)
Definition: math.h:178
#define GET_LOW_WORD(i, d)
Definition: math_private.h:278
double sinh(double x)
Definition: e_sinh.c:37
signed int int32_t
Definition: stdint.h:11
#define expm1(x)
Definition: math.h:177