Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/musl/src/math/asinf.c
4397 views
1
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.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
#include "libm.h"
16
17
static const double
18
pio2 = 1.570796326794896558e+00;
19
20
static const float
21
pio4_hi = 0.785398125648,
22
pio2_lo = 7.54978941586e-08,
23
/* coefficients for R(x^2) */
24
pS0 = 1.66666672e-01,
25
pS1 = -5.11644611e-02,
26
pS2 = -1.21124933e-02,
27
pS3 = -3.58742251e-03,
28
qS1 = -7.56982703e-01;
29
30
static float R(float z)
31
{
32
float_t p, q;
33
p = z*(pS0+z*(pS1+z*(pS2+z*pS3)));
34
q = 1.0f+z*qS1;
35
return p/q;
36
}
37
38
float __cdecl asinf(float x)
39
{
40
float s, z, f, c;
41
uint32_t hx,ix;
42
43
GET_FLOAT_WORD(hx, x);
44
ix = hx & 0x7fffffff;
45
if (ix >= 0x3f800000) { /* |x| >= 1 */
46
if (ix == 0x3f800000) /* |x| == 1 */
47
return x*pio2 + 0x1p-120f; /* asin(+-1) = +-pi/2 with inexact */
48
if (isnan(x)) return x;
49
return math_error(_DOMAIN, "asinf", x, 0, 0 / (x - x));
50
}
51
if (ix < 0x3f000000) { /* |x| < 0.5 */
52
/* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
53
if (ix < 0x39800000 && ix >= 0x00800000)
54
return x;
55
return x + x*R(x*x);
56
}
57
/* 1 > |x| >= 0.5 */
58
z = (1 - fabsf(x))*0.5f;
59
s = sqrtf(z);
60
/* f+c = sqrt(z) */
61
*(unsigned int*)&f = *(unsigned int*)&s & 0xffff0000;
62
c = (z - f * f) / (s + f);
63
x = pio4_hi - (2*s*R(z) - (pio2_lo - 2*c) - (pio4_hi - 2*f));
64
if (hx >> 31)
65
return -x;
66
return x;
67
}
68
69