From ae634ac3a2c467b76409738c9bb3012715302647 Mon Sep 17 00:00:00 2001 From: fdai7848 Date: Sun, 4 Feb 2024 15:29:21 +0100 Subject: [PATCH] add cos function --- src/exponent.h | 1 - src/reihen.c | 21 ++++++++++++++++++++- src/reihen.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/exponent.h b/src/exponent.h index 1264177..e20413c 100644 --- a/src/exponent.h +++ b/src/exponent.h @@ -3,6 +3,5 @@ double p(double exp, double base); double powerD(double exp, double base); -double absD(double x); #endif // exponent.h \ No newline at end of file diff --git a/src/reihen.c b/src/reihen.c index e021325..2190881 100644 --- a/src/reihen.c +++ b/src/reihen.c @@ -42,7 +42,6 @@ double pi(double eps){ } double sinD(double degrees){ - if (degrees>=360.0){ degrees = squashDegreesTo360(degrees); } @@ -60,4 +59,24 @@ double sinD(double degrees){ else sum -= currvalue; } return sum; +} + +double cosD(double degrees){ + if (degrees>=360.0){ + degrees = squashDegreesTo360(degrees); + } + double sum = 0.0; + double currvalue; + double radian = radians(degrees); + double power; + unsigned long long faculty; + for (int i = 0; i <= 9; i++) + { + currvalue = 1.0; + currvalue *= powerD(2*i, radian); + currvalue /= fac(2*i); + if(i%2==0) sum += currvalue; + else sum -= currvalue; + } + return sum; } \ No newline at end of file diff --git a/src/reihen.h b/src/reihen.h index d9cdf38..cb15a78 100644 --- a/src/reihen.h +++ b/src/reihen.h @@ -6,5 +6,6 @@ double euler(); double pi(); double radians(double degrees); double sinD(double degrees); +double cosD(double degrees); #endif // reihen.h \ No newline at end of file