Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/musl/src/math/coshf.c
4397 views
1
#include "libm.h"
2
3
float __cdecl coshf(float x)
4
{
5
union {float f; uint32_t i;} u = {.f = x};
6
uint32_t sign = u.i & 0x80000000;
7
uint32_t w;
8
float t;
9
10
/* |x| */
11
u.i &= 0x7fffffff;
12
x = u.f;
13
w = u.i;
14
15
/* |x| < log(2) */
16
if (w < 0x3f317217) {
17
if (w < 0x3f800000 - (12<<23)) {
18
FORCE_EVAL(x + 0x1p120f);
19
return 1;
20
}
21
t = expm1f(x);
22
return 1 + t*t/(2*(1+t));
23
}
24
25
/* |x| < log(FLT_MAX) */
26
if (w < 0x42b17217) {
27
t = expf(x);
28
return 0.5f*(t + 1/t);
29
}
30
31
/* |x| > log(FLT_MAX) or nan */
32
if (w > 0x7f800000) {
33
u.i |= sign | 0x400000;
34
return u.f;
35
}
36
t = __expo2f(x, 1.0f);
37
return t;
38
}
39
40