xref: /freebsd/contrib/arm-optimized-routines/pl/math/tools/atan.sollya (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1// polynomial for approximating atan(x) and atan2(y, x)
2//
3// Copyright (c) 2022-2023, Arm Limited.
4// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5
6// atan is odd, so approximate with an odd polynomial:
7// x + ax^3 + bx^5 + cx^7 + ...
8// We generate a, b, c, ... such that we can approximate atan(x) by:
9// x + x^3 * (a + bx^2 + cx^4 + ...)
10
11// Assemble monomials
12deg = 20;
13mons = [|1,...,deg|];
14for i from 0 to deg-1 do mons[i] = mons[i] * 2 + 1;
15
16a = 0x1.0p-1022;
17b = 1;
18
19poly = fpminimax(atan(x)-x, mons, [|double ...|], [a;b]);
20
21display = hexadecimal;
22print("coeffs:");
23for i from 0 to deg-1 do coeff(poly,mons[i]);
24