Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / libc / AOR_v20.02 / math / tools / log.sollya
blob41072395eb92ab6b04815d7441b252c9a0ee6077
1 // polynomial for approximating log(1+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 = 12; // poly degree
8 // |log(1+x)| > 0x1p-4 outside the interval
9 a = -0x1p-4;
10 b =  0x1.09p-4;
12 // find log(1+x)/x polynomial with minimal relative error
13 // (minimal relative error polynomial for log(1+x) is the same * x)
14 deg = deg-1; // because of /x
16 // f = log(1+x)/x; using taylor series
17 f = 0;
18 for i from 0 to 60 do { f = f + (-x)^i/(i+1); };
20 // return p that minimizes |f(x) - poly(x) - x^d*p(x)|/|f(x)|
21 approx = proc(poly,d) {
22   return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10);
25 // first coeff is fixed, iteratively find optimal double prec coeffs
26 poly = 1;
27 for i from 1 to deg do {
28   p = roundcoefficients(approx(poly,i), [|D ...|]);
29   poly = poly + x^i*coeff(p,0);
32 display = hexadecimal;
33 print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30));
34 print("in [",a,b,"]");
35 print("coeffs:");
36 for i from 0 to deg do coeff(poly,i);