@@ -93,22 +93,22 @@ LLVM_LIBC_FUNCTION(float16, asinpif16, (float16 x)) {
9393 //
9494 // it's very accurate in the range [0, 0.5] and has a maximum error of
9595 // 0.0000000000000001 in the range [0, 0.5].
96- static constexpr float POLY_COEFFS[10 ] = {
97- 0 .318309886183791f , // x^1
98- 0 .0530516476972984f , // x^3
99- 0 .0238732414637843f , // x^5
100- 0 .0142102627760621f , // x^7
101- 0 .00967087327815336f , // x^9
102- 0 .00712127941391293f , // x^11
103- 0 .00552355646848375f , // x^13
104- 0 .00444514782463692f , // x^15
105- 0 .00367705242846804f , // x^17
106- 0 .00310721681820837f // x^19
96+ static constexpr double POLY_COEFFS[10 ] = {
97+ 0.318309886183791 , // x^1
98+ 0.0530516476972984 , // x^3
99+ 0.0238732414637843 , // x^5
100+ 0.0142102627760621 , // x^7
101+ 0.00967087327815336 , // x^9
102+ 0.00712127941391293 , // x^11
103+ 0.00552355646848375 , // x^13
104+ 0.00444514782463692 , // x^15
105+ 0.00367705242846804 , // x^17
106+ 0.00310721681820837 // x^19
107107 };
108108
109109 // polynomial evaluation using horner's method
110110 // work only for |x| in [0, 0.5]
111- auto asinpi_polyeval = [](float xsq) -> float {
111+ auto asinpi_polyeval = [](double xsq) -> double {
112112 return fputil::polyeval (xsq, POLY_COEFFS[0 ], POLY_COEFFS[1 ], POLY_COEFFS[2 ],
113113 POLY_COEFFS[3 ], POLY_COEFFS[4 ], POLY_COEFFS[5 ],
114114 POLY_COEFFS[6 ], POLY_COEFFS[7 ], POLY_COEFFS[8 ],
@@ -118,8 +118,9 @@ LLVM_LIBC_FUNCTION(float16, asinpif16, (float16 x)) {
118118 // if |x| <= 0.5:
119119 if (LIBC_UNLIKELY (x_abs <= ONE_OVER_TWO)) {
120120 // Use polynomial approximation of asin(x)/pi in the range [0, 0.5]
121- float16 xsq = x * x;
122- float result = x * asinpi_polyeval (xsq);
121+ double xd = static_cast <double >(x);
122+ double xsq = xd * xd;
123+ double result = xd * asinpi_polyeval (xsq);
123124 return fputil::cast<float16>(signed_result (result));
124125 }
125126
@@ -150,11 +151,11 @@ LLVM_LIBC_FUNCTION(float16, asinpif16, (float16 x)) {
150151 // = 0.5 - 0.5 * x
151152 // = multiply_add(-0.5, x, 0.5)
152153
153- float u = static_cast <float >(
154+ double u = static_cast <double >(
154155 fputil::multiply_add (-ONE_OVER_TWO, x_abs, ONE_OVER_TWO));
155- float u_sqrt = fputil::sqrt<float >(static_cast <float >(u));
156- float asinpi_sqrt_u = u_sqrt * asinpi_polyeval (u);
157- float result = fputil::multiply_add (-2 .0f16, asinpi_sqrt_u, ONE_OVER_TWO);
156+ double u_sqrt = fputil::sqrt<double >(static_cast <double >(u));
157+ double asinpi_sqrt_u = u_sqrt * asinpi_polyeval (u);
158+ double result = fputil::multiply_add (-2 .0f16, asinpi_sqrt_u, ONE_OVER_TWO);
158159
159160 return fputil::cast<float16>(signed_result (result));
160161}
0 commit comments