[NFC][Utils] Clone basic blocks after we're done with metadata in CloneFunctionInto...
[llvm-project.git] / libc / AOR_v20.02 / math / tools / sin.sollya
blobf5c11ec2f191be01670b2170d1c737d7695984f3
1 // polynomial for approximating sin(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 = 7;   // polynomial degree
8 a = -pi/4; // interval
9 b = pi/4;
11 // find even polynomial with minimal abs error compared to sin(x)/x
13 // account for /x
14 deg = deg-1;
16 // f = sin(x)/x;
17 f = 1;
18 c = 1;
19 for i from 1 to 60 do { c = 2*i*(2*i + 1)*c; f = f + (-1)^i*x^(2*i)/c; };
21 // return p that minimizes |f(x) - poly(x) - x^d*p(x)|
22 approx = proc(poly,d) {
23   return remez(f(x)-poly(x), deg-d, [a;b], x^d, 1e-10);
26 // first coeff is fixed, iteratively find optimal double prec coeffs
27 poly = 1;
28 for i from 1 to deg/2 do {
29   p = roundcoefficients(approx(poly,2*i), [|D ...|]);
30   poly = poly + x^(2*i)*coeff(p,0);
33 display = hexadecimal;
34 print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30));
35 print("abs error:", accurateinfnorm(sin(x)-x*poly(x), [a;b], 30));
36 print("in [",a,b,"]");
37 print("coeffs:");
38 for i from 0 to deg do coeff(poly,i);