source: trunk/sys/libm/e_sinh.c @ 303

Last change on this file since 303 was 1, checked in by alain, 8 years ago

First import

File size: 2.2 KB
RevLine 
[1]1
2/* @(#)e_sinh.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/* __ieee754_sinh(x)
15 * Method :
16 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
17 *      1. Replace x by |x| (sinh(-x) = -sinh(x)).
18 *      2.
19 *                                                  E + E/(E+1)
20 *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
21 *                                                      2
22 *
23 *          22       <= x <= lnovft :  sinh(x) := exp(x)/2
24 *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
25 *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
26 *
27 * Special cases:
28 *      sinh(x) is |x| if x is +INF, -INF, or NaN.
29 *      only sinh(0)=0 is exact for finite x.
30 */
31
32#include <libm/fdlibm.h>
33
34#ifdef __STDC__
35static const double one = 1.0, shuge = 1.0e307;
36#else
37static double one = 1.0, shuge = 1.0e307;
38#endif
39
40#ifdef __STDC__
41        double __ieee754_sinh(double x)
42#else
43        double __ieee754_sinh(x)
44        double x;
45#endif
46{       
47        double t,w,h;
48        int ix,jx;
49        unsigned lx;
50
51    /* High word of |x|. */
52        jx = *( (((*(int*)&one)>>29)^1) + (int*)&x);
53        ix = jx&0x7fffffff;
54
55    /* x is INF or NaN */
56        if(ix>=0x7ff00000) return x+x; 
57
58        h = 0.5;
59        if (jx<0) h = -h;
60    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
61        if (ix < 0x40360000) {          /* |x|<22 */
62            if (ix<0x3e300000)          /* |x|<2**-28 */
63                if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
64            t = expm1(fabs(x));
65            if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
66            return h*(t+t/(t+one));
67        }
68
69    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
70        if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
71
72    /* |x| in [log(maxdouble), overflowthresold] */
73        lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
74        if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d))) {
75            w = __ieee754_exp(0.5*fabs(x));
76            t = h*w;
77            return t*w;
78        }
79
80    /* |x| > overflowthresold, sinh(x) overflow */
81        return x*shuge;
82}
Note: See TracBrowser for help on using the repository browser.