xref: /freebsd/contrib/arm-optimized-routines/pl/math/tools/log10f.sollya (revision 02e9120893770924227138ba49df1edb3896112a)
1// polynomial for approximating log10f(1+x)
2//
3// Copyright (c) 2019-2023, Arm Limited.
4// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5
6// Computation of log10f(1+x) will be carried out in double precision
7
8deg = 4; // poly degree
9// [OFF; 2*OFF] is divided in 2^4 intervals with OFF~0.7
10a = -0.04375;
11b = 0.04375;
12
13// find log(1+x)/x polynomial with minimal relative error
14// (minimal relative error polynomial for log(1+x) is the same * x)
15deg = deg-1; // because of /x
16
17// f = log(1+x)/x; using taylor series
18f = 0;
19for i from 0 to 60 do { f = f + (-x)^i/(i+1); };
20
21// return p that minimizes |f(x) - poly(x) - x^d*p(x)|/|f(x)|
22approx = proc(poly,d) {
23  return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10);
24};
25
26// first coeff is fixed, iteratively find optimal double prec coeffs
27poly = 1;
28for i from 1 to deg do {
29  p = roundcoefficients(approx(poly,i), [|D ...|]);
30  poly = poly + x^i*coeff(p,0);
31};
32
33display = hexadecimal;
34print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30));
35print("in [",a,b,"]");
36print("coeffs:");
37for i from 0 to deg do double(coeff(poly,i));
38