Skip to content

Commit

Permalink
chore: begin impementing sine function using Taylor series expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
BastianAsmussen committed Jan 9, 2025
1 parent fd7ba76 commit c0fa295
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/math.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ _: rec {

PI = 3.14159265358979323846;

sin = let
s1 = 1.0 / fact 3.0;
s2 = 1.0 / fact 5.0;
s3 = 1.0 / fact 7.0;
s4 = 1.0 / fact 9.0;
s5 = 1.0 / fact 11.0;

polynomial' = xx: (((s5 * xx + s4) * xx + s3) * xx + s2) * xx;
polynomial = xx: (polynomial' xx) + s1;

t = xx: x: dx: ((polynomial xx) * x - 0.5 * dx) * xx + dx;
taylorSin = xx: x: dx: let
dx' =
if x <= 0.0
then -dx
else dx;
in
x + (t xx x dx');
in
x: taylorSin (x * x) x 0.0;

mod = a: n: let
quotient = div a n;
in
Expand Down

0 comments on commit c0fa295

Please sign in to comment.