1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner * Single-precision polynomial evaluation function for scalar
3*f3087befSAndrew Turner * atan(x) and atan2(y,x).
4*f3087befSAndrew Turner *
5*f3087befSAndrew Turner * Copyright (c) 2021-2024, Arm Limited.
6*f3087befSAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
7*f3087befSAndrew Turner */
8*f3087befSAndrew Turner
9*f3087befSAndrew Turner #ifndef PL_MATH_ATANF_COMMON_H
10*f3087befSAndrew Turner #define PL_MATH_ATANF_COMMON_H
11*f3087befSAndrew Turner
12*f3087befSAndrew Turner #include "math_config.h"
13*f3087befSAndrew Turner #include "poly_scalar_f32.h"
14*f3087befSAndrew Turner
15*f3087befSAndrew Turner /* Polynomial used in fast atanf(x) and atan2f(y,x) implementations
16*f3087befSAndrew Turner The order 7 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2). */
17*f3087befSAndrew Turner static inline float
eval_poly(float z,float az,float shift)18*f3087befSAndrew Turner eval_poly (float z, float az, float shift)
19*f3087befSAndrew Turner {
20*f3087befSAndrew Turner /* Use 2-level Estrin scheme for P(z^2) with deg(P)=7. However,
21*f3087befSAndrew Turner a standard implementation using z8 creates spurious underflow
22*f3087befSAndrew Turner in the very last fma (when z^8 is small enough).
23*f3087befSAndrew Turner Therefore, we split the last fma into a mul and and an fma.
24*f3087befSAndrew Turner Horner and single-level Estrin have higher errors that exceed
25*f3087befSAndrew Turner threshold. */
26*f3087befSAndrew Turner float z2 = z * z;
27*f3087befSAndrew Turner float z4 = z2 * z2;
28*f3087befSAndrew Turner
29*f3087befSAndrew Turner /* Then assemble polynomial. */
30*f3087befSAndrew Turner float y = fmaf (
31*f3087befSAndrew Turner z4, z4 * pairwise_poly_3_f32 (z2, z4, __atanf_poly_data.poly + 4),
32*f3087befSAndrew Turner pairwise_poly_3_f32 (z2, z4, __atanf_poly_data.poly));
33*f3087befSAndrew Turner /* Finalize:
34*f3087befSAndrew Turner y = shift + z * P(z^2). */
35*f3087befSAndrew Turner return fmaf (y, z2 * az, az) + shift;
36*f3087befSAndrew Turner }
37*f3087befSAndrew Turner
38*f3087befSAndrew Turner #endif // PL_MATH_ATANF_COMMON_H
39