diff options
author | Joe Ramsay <Joe.Ramsay@arm.com> | 2022-07-12 12:25:09 +0100 |
---|---|---|
committer | Joe Ramsay <joe.ramsay@arm.com> | 2022-07-12 12:25:09 +0100 |
commit | c6e5af7d30eb825f53ec7596021f7237a0ca23e3 (patch) | |
tree | be17246f896644f49f22ec3bef4d2e73c020d918 /pl/math/tools/log1p.sollya | |
parent | d082d55feea607f231358cc49a958da419fac537 (diff) | |
download | arm-optimized-routines-c6e5af7d30eb825f53ec7596021f7237a0ca23e3.tar.gz |
pl/math: Add scalar log1p
New routine uses a polynomial on reduced interval. Worst-case error is
about 1.7 ULP.
Diffstat (limited to 'pl/math/tools/log1p.sollya')
-rw-r--r-- | pl/math/tools/log1p.sollya | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pl/math/tools/log1p.sollya b/pl/math/tools/log1p.sollya new file mode 100644 index 0000000..fb159b3 --- /dev/null +++ b/pl/math/tools/log1p.sollya @@ -0,0 +1,30 @@ +// polynomial for approximating log(1+x) in double precision +// +// Copyright (c) 2022, Arm Limited. +// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + +deg = 20; + +a = sqrt(2)/2-1; +b = sqrt(2)-1; + +f = proc(y) { + return log(1+y); +}; + +approx = proc(poly, d) { + return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10); +}; + +poly = x; +for i from 2 to deg do { + p = roundcoefficients(approx(poly,i), [|D ...|]); + poly = poly + x^i*coeff(p,0); +}; + + +print("coeffs:"); +display = hexadecimal; +for i from 2 to deg do coeff(poly,i); +print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30)); +print("in [",a,b,"]"); |