Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/musl/src/math/acosf.c
4397 views
1
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosf.c */
2
/*
3
* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
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
19
pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
20
pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
21
pS0 = 1.66666672e-01,
22
pS1 = -5.11644611e-02,
23
pS2 = -1.21124933e-02,
24
pS3 = -3.58742251e-03,
25
qS1 = -7.56982703e-01;
26
27
static float R(float z)
28
{
29
float_t p, q;
30
p = z*(pS0+z*(pS1+z*(pS2+z*pS3)));
31
q = 1.0f+z*qS1;
32
return p/q;
33
}
34
35
float __cdecl acosf(float x)
36
{
37
float z,w,s,c,df;
38
uint32_t hx,ix;
39
40
GET_FLOAT_WORD(hx, x);
41
ix = hx & 0x7fffffff;
42
/* |x| >= 1 or nan */
43
if (ix >= 0x3f800000) {
44
if (ix == 0x3f800000) {
45
if (hx >> 31)
46
return M_PI;
47
return 0;
48
}
49
if (isnan(x)) return x;
50
return math_error(_DOMAIN, "acosf", x, 0, 0 / (x - x));
51
}
52
/* |x| < 0.5 */
53
if (ix < 0x3f000000) {
54
if (ix <= 0x32800000) /* |x| < 2**-26 */
55
return M_PI_2;
56
return pio2_hi - (x - (pio2_lo-x*R(x*x)));
57
}
58
/* x < -0.5 */
59
if (hx >> 31) {
60
z = (1+x)*0.5f;
61
s = sqrtf(z);
62
return 2*(pio2_hi - (s + (R(z)*s-pio2_lo)));
63
}
64
/* x > 0.5 */
65
z = (1-x)*0.5f;
66
s = sqrtf(z);
67
GET_FLOAT_WORD(hx,s);
68
SET_FLOAT_WORD(df,hx&0xfffff000);
69
c = (z-df*df)/(s+df);
70
w = R(z)*s+c;
71
return 2*(df+w);
72
}
73
74