[InstCombine] Drop range attributes in `foldBitCeil` (#116641)
[llvm-project.git] / libc / AOR_v20.02 / math / tools / exp2.sollya
blob7980eefbff5ff204e65c4c2da66488381be9623f
1 // polynomial for approximating 2^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 // exp2f parameters
8 deg = 3; // poly degree
9 N = 32;  // table entries
10 b = 1/(2*N); // interval
11 a = -b;
13 //// exp2 parameters
14 //deg = 5; // poly degree
15 //N = 128; // table entries
16 //b = 1/(2*N); // interval
17 //a = -b;
19 // find polynomial with minimal relative error
21 f = 2^x;
23 // return p that minimizes |f(x) - poly(x) - x^d*p(x)|/|f(x)|
24 approx = proc(poly,d) {
25   return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10);
27 // return p that minimizes |f(x) - poly(x) - x^d*p(x)|
28 approx_abs = proc(poly,d) {
29   return remez(f(x) - poly(x), deg-d, [a;b], x^d, 1e-10);
32 // first coeff is fixed, iteratively find optimal double prec coeffs
33 poly = 1;
34 for i from 1 to deg do {
35   p = roundcoefficients(approx(poly,i), [|D ...|]);
36 //  p = roundcoefficients(approx_abs(poly,i), [|D ...|]);
37   poly = poly + x^i*coeff(p,0);
40 display = hexadecimal;
41 print("rel error:", accurateinfnorm(1-poly(x)/2^x, [a;b], 30));
42 print("abs error:", accurateinfnorm(2^x-poly(x), [a;b], 30));
43 print("in [",a,b,"]");
44 // double interval error for non-nearest rounding:
45 print("rel2 error:", accurateinfnorm(1-poly(x)/2^x, [2*a;2*b], 30));
46 print("abs2 error:", accurateinfnorm(2^x-poly(x), [2*a;2*b], 30));
47 print("in [",2*a,2*b,"]");
48 print("coeffs:");
49 for i from 0 to deg do coeff(poly,i);