~ubuntu-branches/ubuntu/precise/eglibc/precise-201308281639

« back to all changes in this revision

Viewing changes to sysdeps/ieee754/dbl-64/e_cosh.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-02-08 01:58:09 UTC
  • mfrom: (1.5.3) (288.1.12 precise)
  • Revision ID: package-import@ubuntu.com-20120208015809-ulscst7uteq3e22z
Tags: 2.15~pre6-0ubuntu10
Merge from Debian (r5151, 2.13-26).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* @(#)e_cosh.c 5.1 93/09/24 */
 
1
/* Optimized by Ulrich Drepper <drepper@gmail.com>, 2011 */
2
2
/*
3
3
 * ====================================================
4
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
5
 *
6
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
7
 * Permission to use, copy, modify, and distribute this
8
 
 * software is freely granted, provided that this notice 
 
8
 * software is freely granted, provided that this notice
9
9
 * is preserved.
10
10
 * ====================================================
11
11
 */
12
12
 
13
 
#if defined(LIBM_SCCS) && !defined(lint)
14
 
static char rcsid[] = "$NetBSD: e_cosh.c,v 1.7 1995/05/10 20:44:58 jtc Exp $";
15
 
#endif
16
 
 
17
13
/* __ieee754_cosh(x)
18
 
 * Method : 
 
14
 * Method :
19
15
 * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
20
 
 *      1. Replace x by |x| (cosh(x) = cosh(-x)). 
21
 
 *      2. 
22
 
 *                                                      [ exp(x) - 1 ]^2 
 
16
 *      1. Replace x by |x| (cosh(x) = cosh(-x)).
 
17
 *      2.
 
18
 *                                                      [ exp(x) - 1 ]^2
23
19
 *          0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------
24
 
 *                                                         2*exp(x)
 
20
 *                                                         2*exp(x)
25
21
 *
26
 
 *                                                exp(x) +  1/exp(x)
 
22
 *                                                exp(x) +  1/exp(x)
27
23
 *          ln2/2    <= x <= 22     :  cosh(x) := -------------------
28
 
 *                                                        2
29
 
 *          22       <= x <= lnovft :  cosh(x) := exp(x)/2 
 
24
 *                                                        2
 
25
 *          22       <= x <= lnovft :  cosh(x) := exp(x)/2
30
26
 *          lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)
31
27
 *          ln2ovft  <  x           :  cosh(x) := huge*huge (overflow)
32
28
 *
38
34
#include "math.h"
39
35
#include "math_private.h"
40
36
 
41
 
#ifdef __STDC__
42
37
static const double one = 1.0, half=0.5, huge = 1.0e300;
43
 
#else
44
 
static double one = 1.0, half=0.5, huge = 1.0e300;
45
 
#endif
46
38
 
47
 
#ifdef __STDC__
48
 
        double __ieee754_cosh(double x)
49
 
#else
50
 
        double __ieee754_cosh(x)
51
 
        double x;
52
 
#endif
53
 
{       
 
39
double
 
40
__ieee754_cosh (double x)
 
41
{
54
42
        double t,w;
55
43
        int32_t ix;
56
44
        u_int32_t lx;
59
47
        GET_HIGH_WORD(ix,x);
60
48
        ix &= 0x7fffffff;
61
49
 
62
 
    /* x is INF or NaN */
63
 
        if(ix>=0x7ff00000) return x*x;  
64
 
 
65
 
    /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
66
 
        if(ix<0x3fd62e43) {
67
 
            t = __expm1(fabs(x));
68
 
            w = one+t;
69
 
            if (ix<0x3c800000) return w;        /* cosh(tiny) = 1 */
70
 
            return one+(t*t)/(w+w);
71
 
        }
72
 
 
73
 
    /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
 
50
    /* |x| in [0,22] */
74
51
        if (ix < 0x40360000) {
 
52
            /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
 
53
                if(ix<0x3fd62e43) {
 
54
                    t = __expm1(fabs(x));
 
55
                    w = one+t;
 
56
                    if (ix<0x3c800000) return w;        /* cosh(tiny) = 1 */
 
57
                    return one+(t*t)/(w+w);
 
58
                }
 
59
 
 
60
            /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
75
61
                t = __ieee754_exp(fabs(x));
76
62
                return half*t+half/t;
77
63
        }
87
73
            return t*w;
88
74
        }
89
75
 
 
76
    /* x is INF or NaN */
 
77
        if(ix>=0x7ff00000) return x*x;
 
78
 
90
79
    /* |x| > overflowthresold, cosh(x) overflow */
91
80
        return huge*huge;
92
81
}
 
82
strong_alias (__ieee754_cosh, __cosh_finite)