xref: /freebsd/contrib/arm-optimized-routines/pl/math/tools/log1p.sollya (revision a90b9d0159070121c221b966469c3e36d912bf82)
1// polynomial for approximating log(1+x) in double precision
2//
3// Copyright (c) 2022-2023, Arm Limited.
4// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5
6deg = 20;
7
8a = sqrt(2)/2-1;
9b = sqrt(2)-1;
10
11f = proc(y) {
12  return log(1+y);
13};
14
15approx = proc(poly, d) {
16  return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10);
17};
18
19poly = x;
20for i from 2 to deg do {
21  p = roundcoefficients(approx(poly,i), [|D ...|]);
22  poly = poly + x^i*coeff(p,0);
23};
24
25
26print("coeffs:");
27display = hexadecimal;
28for i from 2 to deg do coeff(poly,i);
29print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30));
30print("in [",a,b,"]");
31