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