xref: /aosp_15_r20/external/arm-optimized-routines/pl/math/atan_common.h (revision 412f47f9e737e10ed5cc46ec6a8d7fa2264f8a14)
1*412f47f9SXin Li /*
2*412f47f9SXin Li  * Double-precision polynomial evaluation function for scalar
3*412f47f9SXin Li  * atan(x) and atan2(y,x).
4*412f47f9SXin Li  *
5*412f47f9SXin Li  * Copyright (c) 2021-2023, Arm Limited.
6*412f47f9SXin Li  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
7*412f47f9SXin Li  */
8*412f47f9SXin Li 
9*412f47f9SXin Li #include "math_config.h"
10*412f47f9SXin Li #include "poly_scalar_f64.h"
11*412f47f9SXin Li 
12*412f47f9SXin Li /* Polynomial used in fast atan(x) and atan2(y,x) implementations
13*412f47f9SXin Li    The order 19 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2).  */
14*412f47f9SXin Li static inline double
eval_poly(double z,double az,double shift)15*412f47f9SXin Li eval_poly (double z, double az, double shift)
16*412f47f9SXin Li {
17*412f47f9SXin Li   /* Use split Estrin scheme for P(z^2) with deg(P)=19. Use split instead of
18*412f47f9SXin Li      full scheme to avoid underflow in x^16.  */
19*412f47f9SXin Li   double z2 = z * z;
20*412f47f9SXin Li   double x2 = z2 * z2;
21*412f47f9SXin Li   double x4 = x2 * x2;
22*412f47f9SXin Li   double x8 = x4 * x4;
23*412f47f9SXin Li   double y = fma (estrin_11_f64 (z2, x2, x4, x8, __atan_poly_data.poly + 8),
24*412f47f9SXin Li 		  x8, estrin_7_f64 (z2, x2, x4, __atan_poly_data.poly));
25*412f47f9SXin Li 
26*412f47f9SXin Li   /* Finalize. y = shift + z + z^3 * P(z^2).  */
27*412f47f9SXin Li   y = fma (y, z2 * az, az);
28*412f47f9SXin Li   y = y + shift;
29*412f47f9SXin Li 
30*412f47f9SXin Li   return y;
31*412f47f9SXin Li }
32*412f47f9SXin Li 
33*412f47f9SXin Li #undef P
34