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