POK
e_sinh.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* @(#)e_sinh.c 5.1 93/09/24 */
18 /*
19  * ====================================================
20  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
21  *
22  * Developed at SunPro, a Sun Microsystems, Inc. business.
23  * Permission to use, copy, modify, and distribute this
24  * software is freely granted, provided that this notice
25  * is preserved.
26  * ====================================================
27  */
28 
29 /* __ieee754_sinh(x)
30  * Method :
31  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
32  * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
33  * 2.
34  * E + E/(E+1)
35  * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
36  * 2
37  *
38  * 22 <= x <= lnovft : sinh(x) := exp(x)/2
39  * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
40  * ln2ovft < x : sinh(x) := x*shuge (overflow)
41  *
42  * Special cases:
43  * sinh(x) is |x| if x is +INF, -INF, or NaN.
44  * only sinh(0)=0 is exact for finite x.
45  */
46 
47 #ifdef POK_NEEDS_LIBMATH
48 
49 #include <libm.h>
50 #include "math_private.h"
51 
52 static const double one = 1.0, shuge = 1.0e307;
53 
54 double
55 __ieee754_sinh(double x)
56 {
57  double t,w,h;
58  int32_t ix,jx;
59  uint32_t lx;
60 
61  /* High word of |x|. */
62  GET_HIGH_WORD(jx,x);
63  ix = jx&0x7fffffff;
64 
65  /* x is INF or NaN */
66  if(ix>=0x7ff00000) return x+x;
67 
68  h = 0.5;
69  if (jx<0) h = -h;
70  /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
71  if (ix < 0x40360000) { /* |x|<22 */
72  if (ix<0x3e300000) /* |x|<2**-28 */
73  if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
74  t = expm1(fabs(x));
75  if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
76  return h*(t+t/(t+one));
77  }
78 
79  /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
80  if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
81 
82  /* |x| in [log(maxdouble), overflowthresold] */
83  GET_LOW_WORD(lx,x);
84  if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d))) {
85  w = __ieee754_exp(0.5*fabs(x));
86  t = h*w;
87  return t*w;
88  }
89 
90  /* |x| > overflowthresold, sinh(x) overflow */
91  return x*shuge;
92 }
93 #endif
94