assembly optimizations for fmod/remainder functions
[musl] / src / math / coshf.c
1 /* origin: FreeBSD /usr/src/lib/msun/src/e_coshf.c */
2 /*
3  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
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 "libm.h"
17
18 static const float one = 1.0, half = 0.5, huge = 1.0e30;
19
20 float coshf(float x)
21 {
22         float t, w;
23         int32_t ix;
24
25         GET_FLOAT_WORD(ix, x);
26         ix &= 0x7fffffff;
27
28         /* x is INF or NaN */
29         if (ix >= 0x7f800000)
30                 return x*x;
31
32         /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
33         if (ix < 0x3eb17218) {
34                 t = expm1f(fabsf(x));
35                 w = one+t;
36                 if (ix<0x39800000)
37                         return one;  /* cosh(tiny) = 1 */
38                 return one + (t*t)/(w+w);
39         }
40
41         /* |x| in [0.5*ln2,9], return (exp(|x|)+1/exp(|x|))/2; */
42         if (ix < 0x41100000) {
43                 t = expf(fabsf(x));
44                 return half*t + half/t;
45         }
46
47         /* |x| in [9, log(maxfloat)] return half*exp(|x|) */
48         if (ix < 0x42b17217)
49                 return half*expf(fabsf(x));
50
51         /* |x| in [log(maxfloat), overflowthresold] */
52         if (ix <= 0x42b2d4fc)
53                 return __expo2f(fabsf(x));
54
55         /* |x| > overflowthresold, cosh(x) overflow */
56         return huge*huge;
57 }