#include "math.h"
#include "math_private.h"
#define _CC (0x1p57L + 1)
#define _ROOT sqrtl
volatile static const double tiny = 1.e-300;
static const double half = 0.5, one = 1.;
static const long double
invpihi = 3.18309886183790671537767526745028737e-01L,
invpilo = -1.28821588763206006125693864783127482e-35L;
static inline long double
__r(long double xs)
{
static const long double
R0 = 5.30516476972984452562945877908381207e-02L,
R1 = -2.60404681812983888677486288898051068e-01L,
R2 = 5.43274368732204127849880302812989126e-01L,
R3 = -6.27476039646895838848725721148947475e-01L,
R4 = 4.37806223811161460670580937913479055e-01L,
R5 = -1.88854683672201011042310131486279147e-01L,
R6 = 4.94528645546233985859708428238164776e-02L,
R7 = -7.38228286468784921885881430313681146e-03L,
R8 = 5.47609957562826794808966842094709768e-04L,
R9 = -1.44837427671490633843418618030301533e-05L,
R10= 1.60087061374239702655150492329207605e-08L,
S1 = -5.35851261206434695164324875722635942e+00L,
S2 = 1.23839541267281630422432341920191869e+01L,
S3 = -1.61473998442126533731585929134597693e+01L,
S4 = 1.30442314991246752613457576698550221e+01L,
S5 = -6.74685395302389922545194846871599697e+00L,
S6 = 2.22958089278066716953022085768628547e+00L,
S7 = -4.55313732093612723575589438727154778e-01L,
S8 = 5.33391487207251214709627478847204628e-02L,
S9 = -3.08343599417750507732125775680767303e-03L,
S10= 6.12260957946655623349049151336307244e-05L;
long double r, s;
r = R5 + (R6 + (R7 + (R8 + (R9 + R10 * xs) * xs) *xs) * xs) * xs;
r = R0 + (R1 + (R2 + (R3 + (R4 + r * xs) * xs) * xs) * xs) * xs;
s = S5 + (S6 + (S7 + (S8 + (S9 + S10 * xs) * xs) *xs) * xs) * xs;
s = 1 + (S1 + (S2 + (S3 + (S4 + r * xs) * xs) * xs) * xs) * xs;
return (xs * (r / s));
}
long double
asinpil(long double x)
{
long double ax, hi, lo, xh, xl, y, zh, zl;
if (isnan(x) || isinf(x))
return ((x - x) / (x - x));
ax = fabsl(x);
if (ax > 1)
return ((x - x) / (x - x));
if (ax <= 0.5) {
if (ax < 0x1p-57L) {
if (ax < 0x1p-16340L) {
if (ax == 0)
return (x);
ax *= 0x1p114;
_XMUL(ax, 0, invpihi, invpilo, hi, lo);
y = (hi + lo) * 0x1p-114;
} else {
_XMUL(ax, 0, invpihi, invpilo, hi, lo);
y = hi + lo;
}
} else {
y = __r(ax * ax);
_XADD(invpihi, invpilo, y, 0, xh, xl);
_XMUL(ax, 0, xh, xl, hi, lo);
y = hi + lo;
}
} else if (ax < 1) {
y = 1 - ax;
x = __r(y / 2);
_XADD(invpihi, invpilo, x, 0, xh, xl);
_SQRT(2 * y, zh, zl);
_XMUL(xh, xl, zh, zl, hi, lo);
_XADD(half, 0, -hi, -lo, y, x);
} else
y = half;
return (x < 0 ? -y : y);
}
long double
acospil(long double x)
{
long double ax, hi, lo, xh, xl, y, zh, zl;
if (isnan(x) || isinf(x))
return ((x - x) / (x - x));
ax = fabsl(x);
if (ax > 1)
return ((x - x) / (x - x));
if (ax <= 0.5) {
if (ax < 0x1p-55L) {
y = (ax == 0) ? half : (ax < 0x1p-113 ?
half - tiny : half - x * invpihi);
} else {
y = __r(x * x);
_XADD(invpihi, invpilo, y, 0, xh, xl);
_XMUL(x, 0, xh, xl, hi, lo);
_XADD(half, 0, -hi, -lo, y, ax);
}
} else if (ax < 1) {
y = 1 - ax;
ax = __r(y / 2);
_XADD(invpihi, invpilo, ax, 0, xh, xl);
_SQRT(2 * y, zh, zl);
_XMUL(xh, xl, zh, zl, hi, lo);
if (x < 0)
_XADD(one, 0, -hi, -lo, y, ax);
else
y = hi + lo;
} else
y = half;
return (y);
}