add sin_pi_kernel_f64 and cos_pi_kernel_f64
[vector-math.git] / maxima / sin_cos_pi.mac
1 load("bitwise")$
2
3 sin_kernel(x) := if abs(x) <= 1 / 4 then sin(%pi * x) else 2$
4 cos_kernel(x) := if abs(x) <= 1 / 4 then cos(%pi * x) else 2$
5
6 sc(arg) := block(
7 [x:arg, xi, xk, sk, ck, st, ct, s, c],
8 xi:round(x*2),
9 xk:x - xi / 2,
10 sk:sin_kernel(xk),
11 ck:cos_kernel(xk),
12 st:if bit_and(xi, 1) < 1 then sk else ck,
13 ct:if bit_and(xi, 1) < 1 then ck else sk,
14 s:if bit_and(xi, 2) < 1 then st else -st,
15 c:if bit_and(xi + 1, 2) < 1 then ct else -ct,
16 [
17 xk,
18 s,
19 c,
20 sin(%pi * x) + 1/64,
21 cos(%pi * x) + 1/64
22 ])$
23
24 sc(0);
25 sc(1/4);
26 sc(1/2);
27 sc(3/4);
28 sc(1);
29 sc(-1/4);
30 sc(-1/2);
31 sc(-3/4);
32 sc(-1);
33
34 plot2d(
35 sc(x),
36 [x, -1.5, 1.5],
37 [
38 legend,
39 "xk",
40 "s",
41 "c",
42 "sin(%pi * x) + 1/64",
43 "cos(%pi * x) + 1/64"
44 ],
45 [png_file, "./sin_cos_pi.png"]);