1df930be7Sderaadt /* e_coshf.c -- float version of e_cosh.c.
2df930be7Sderaadt * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3df930be7Sderaadt */
4df930be7Sderaadt
5df930be7Sderaadt /*
6df930be7Sderaadt * ====================================================
7df930be7Sderaadt * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8df930be7Sderaadt *
9df930be7Sderaadt * Developed at SunPro, a Sun Microsystems, Inc. business.
10df930be7Sderaadt * Permission to use, copy, modify, and distribute this
11df930be7Sderaadt * software is freely granted, provided that this notice
12df930be7Sderaadt * is preserved.
13df930be7Sderaadt * ====================================================
14df930be7Sderaadt */
15df930be7Sderaadt
16df930be7Sderaadt #include "math.h"
17df930be7Sderaadt #include "math_private.h"
18df930be7Sderaadt
19df930be7Sderaadt static const volatile float huge = 1.0e30;
20df930be7Sderaadt static const float one = 1.0, half=0.5;
21df930be7Sderaadt
22e7beb4a7Smillert float
coshf(float x)237b36286aSmartynas coshf(float x)
24df930be7Sderaadt {
25df930be7Sderaadt float t,w;
26df930be7Sderaadt int32_t ix;
27df930be7Sderaadt
28df930be7Sderaadt GET_FLOAT_WORD(ix,x);
29df930be7Sderaadt ix &= 0x7fffffff;
30df930be7Sderaadt
31df930be7Sderaadt /* x is INF or NaN */
32df930be7Sderaadt if(ix>=0x7f800000) return x*x;
33df930be7Sderaadt
34df930be7Sderaadt /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
35df930be7Sderaadt if(ix<0x3eb17218) {
36df930be7Sderaadt t = expm1f(fabsf(x));
37df930be7Sderaadt w = one+t;
38df930be7Sderaadt if (ix<0x24000000) return w; /* cosh(tiny) = 1 */
39df930be7Sderaadt return one+(t*t)/(w+w);
40df930be7Sderaadt }
41df930be7Sderaadt
42df930be7Sderaadt /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
43df930be7Sderaadt if (ix < 0x41b00000) {
447b36286aSmartynas t = expf(fabsf(x));
45df930be7Sderaadt return half*t+half/t;
46df930be7Sderaadt }
47df930be7Sderaadt
48df930be7Sderaadt /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
497b36286aSmartynas if (ix < 0x42b17180) return half*expf(fabsf(x));
50df930be7Sderaadt
51df930be7Sderaadt /* |x| in [log(maxdouble), overflowthresold] */
52df930be7Sderaadt if (ix<=0x42b2d4fc) {
537b36286aSmartynas w = expf(half*fabsf(x));
54df930be7Sderaadt t = half*w;
55df930be7Sderaadt return t*w;
56df930be7Sderaadt }
57df930be7Sderaadt
58df930be7Sderaadt /* |x| > overflowthresold, cosh(x) overflow */
59df930be7Sderaadt return huge*huge;
60df930be7Sderaadt }
61*2f2c0062Sguenther DEF_STD(coshf);
62