1 /* ef_cosh.c -- float version of e_cosh.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4 
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15 
16 #include "fdlibm.h"
17 #include "math_config.h"
18 
19 #ifdef __v810__
20 #define const
21 #endif
22 
23 static const float one = 1.0, half = 0.5;
24 
25 float
coshf(float x)26 coshf(float x)
27 {
28     float t, w;
29     __int32_t ix;
30 
31     GET_FLOAT_WORD(ix, x);
32     ix &= 0x7fffffff;
33 
34     x = fabsf(x);
35 
36     /* x is INF or NaN */
37     if (!FLT_UWORD_IS_FINITE(ix))
38         return x + x;
39 
40     /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
41     if (ix < 0x3eb17218) {
42         t = expm1f(x);
43         w = one + t;
44         if (ix < 0x24000000)
45             return w; /* cosh(tiny) = 1 */
46         return one + (t * t) / (w + w);
47     }
48 
49     /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
50     if (ix < 0x41b00000) {
51         t = expf(x);
52         return half * t + half / t;
53     }
54 
55     /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
56     if (ix <= FLT_UWORD_LOG_MAX)
57         return half * expf(x);
58 
59     /* |x| in [log(maxdouble), overflowthresold] */
60     if (ix <= FLT_UWORD_LOG_2MAX) {
61         w = expf(half * x);
62         t = half * w;
63         return t * w;
64     }
65 
66     /* |x| > overflowthresold, cosh(x) overflow */
67     return __math_oflowf(0);
68 }
69 
70 _MATH_ALIAS_f_f(cosh)
71