Browse Source

refactoring: reduce use of variables in sin and cos function and delete print functions in tests

master
fdai7848 11 months ago
parent
commit
9feab8998d
  1. 30
      src/reihen.c
  2. 5
      test/test_reihen.c

30
src/reihen.c

@ -45,19 +45,14 @@ double sinD(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+1, radian);
currvalue /= (double) fac(2*i+1);
if(i%2==0) sum += currvalue;
else sum -= currvalue;
for (int i = 0; i <= 9; i++){
sum += powerD((double) i, -1.0) * (powerD(2.0*i+1, radian) / fac(2.0*i+1));
}
return sum;
}
@ -65,19 +60,14 @@ 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;
for (int i = 0; i <= 9; i++){
sum += powerD((double) i, -1.0) * (powerD(2*i, radian) / fac(2*i));
}
return sum;
}

5
test/test_reihen.c

@ -81,11 +81,6 @@ void test_cos(void){
r3 = cosD(36.97);
r4 = cosD(180.0);
printf("%lf\n", r1);
printf("%lf\n", r2);
printf("%lf\n", r3);
printf("%lf\n", r4);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.642787, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.0, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.798950, r3);

Loading…
Cancel
Save