diff --git a/src/exponent.c b/src/exponent.c index 8909d56..2e0d5b3 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -5,13 +5,7 @@ #include "exponent.h" #include "logarithmus.h" #include "reihen.h" - -double absD(double x){ - if(x<0){ - return -1 * x; - } - return x; -} +#include "util.h" double p(double exp, double base){ double prod = 1.0; diff --git a/src/logarithmus.c b/src/logarithmus.c index fa6ea62..2d440f9 100644 --- a/src/logarithmus.c +++ b/src/logarithmus.c @@ -4,6 +4,7 @@ #include "logarithmus.h" #include "exponent.h" #include "reihen.h" +#include "util.h" double logX(double base, double value){ if(base == 1.0 || base <= 0.0 || value <= 0.0){ diff --git a/src/reihen.c b/src/reihen.c index 649814a..e021325 100644 --- a/src/reihen.c +++ b/src/reihen.c @@ -5,21 +5,10 @@ #include "reihen.h" #include "exponent.h" #include "logarithmus.h" +#include "util.h" #define PI pi(1e-8) -unsigned long long fac(int x){ - unsigned long long prod = 1; - if(x==0) return 1; - for (int i = 1; i <= x; i++){ - if (prod > ULLONG_MAX / i){ - break; - } - prod*=i; - } - return prod; -} - double exponential(double exp){ double sum = 0.0; for(int i = 0; i<=21; i++){ @@ -32,10 +21,6 @@ double euler(){ return exponential(1); } -double squashDegreesTo360(double degrees){ - int multiple = degrees / 360; - return degrees - (360*multiple); -} double radians(double degrees){ return degrees * PI / 180; diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..6930ec9 --- /dev/null +++ b/src/util.c @@ -0,0 +1,28 @@ +#include +#include + +#include "util.h" + +double absD(double x){ + if(x<0){ + return -1 * x; + } + return x; +} + +double squashDegreesTo360(double degrees){ + int multiple = degrees / 360; + return degrees - (360*multiple); +} + +unsigned long long fac(int x){ + unsigned long long prod = 1; + if(x==0) return 1; + for (int i = 1; i <= x; i++){ + if (prod > ULLONG_MAX / i){ + break; + } + prod*=i; + } + return prod; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..76eb4ba --- /dev/null +++ b/src/util.h @@ -0,0 +1,8 @@ +#ifndef UTIL_H +#define UTIL_H + +double absD(double x); +double squashDegreesTo360(double degrees); +unsigned long long fac(int x); + +#endif // util.h \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index d137507..bd2fdda 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -5,6 +5,7 @@ #include "exponent.h" #include "logarithmus.h" #include "reihen.h" +#include "util.h" void setUp(void) { diff --git a/test/test_logarithmus.c b/test/test_logarithmus.c index 7c24c13..e8f8da9 100644 --- a/test/test_logarithmus.c +++ b/test/test_logarithmus.c @@ -5,6 +5,7 @@ #include "logarithmus.h" #include "exponent.h" #include "reihen.h" +#include "util.h" void setUp(void) { diff --git a/test/test_reihen.c b/test/test_reihen.c index a24ecb7..f75c8fa 100644 --- a/test/test_reihen.c +++ b/test/test_reihen.c @@ -5,6 +5,7 @@ #include "reihen.h" #include "exponent.h" #include "logarithmus.h" +#include "util.h" void setUp(void) {