[Workflow] Roll back some settings since they caused more issues
[llvm-project.git] / libc / AOR_v20.02 / math / tools / v_exp.sollya
blob4ef477f9002008fb3a3d15afa3504998db1e070a
1 // polynomial for approximating e^x
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 deg = 4; // poly degree
8 N = 128; // table entries
9 b = log(2)/(2*N);  // interval
10 a = -b;
12 // find polynomial with minimal abs error
14 // return p that minimizes |exp(x) - poly(x) - x^d*p(x)|
15 approx = proc(poly,d) {
16   return remez(exp(x)-poly(x), deg-d, [a;b], x^d, 1e-10);
19 // first 2 coeffs are fixed, iteratively find optimal double prec coeffs
20 poly = 1 + x;
21 for i from 2 to deg do {
22   p = roundcoefficients(approx(poly,i), [|D ...|]);
23   poly = poly + x^i*coeff(p,0);
26 display = hexadecimal;
27 print("rel error:", accurateinfnorm(1-poly(x)/exp(x), [a;b], 30));
28 print("abs error:", accurateinfnorm(exp(x)-poly(x), [a;b], 30));
29 print("in [",a,b,"]");
30 print("coeffs:");
31 for i from 0 to deg do coeff(poly,i);