aboutsummaryrefslogtreecommitdiff
path: root/pl/math/atan_common.h
blob: da0da643685471d667b338098e9f9b18d9060a92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Double-precision polynomial evaluation function for scalar and vector atan(x)
 * and atan2(y,x).
 *
 * Copyright (c) 2021-2023, Arm Limited.
 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
 */

#include "math_config.h"
#include "estrin.h"

#if V_SUPPORTED

#include "v_math.h"

#define DBL_T v_f64_t
#define P(i) v_f64 (__atan_poly_data.poly[i])

#else

#define DBL_T double
#define P(i) __atan_poly_data.poly[i]

#endif

/* Polynomial used in fast atan(x) and atan2(y,x) implementations
   The order 19 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2).  */
static inline DBL_T
eval_poly (DBL_T z, DBL_T az, DBL_T shift)
{
  /* Use split Estrin scheme for P(z^2) with deg(P)=19. Use split instead of
     full scheme to avoid underflow in x^16.  */
  DBL_T z2 = z * z;
  DBL_T x2 = z2 * z2;
  DBL_T x4 = x2 * x2;
  DBL_T x8 = x4 * x4;
  DBL_T y
    = FMA (ESTRIN_11_ (z2, x2, x4, x8, P, 8), x8, ESTRIN_7 (z2, x2, x4, P));

  /* Finalize. y = shift + z + z^3 * P(z^2).  */
  y = FMA (y, z2 * az, az);
  y = y + shift;

  return y;
}

#undef DBL_T
#undef FMA
#undef P