diff --git a/src/exponent.c b/src/exponent.c index bbe2221..8909d56 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -4,6 +4,7 @@ #include "exponent.h" #include "logarithmus.h" +#include "reihen.h" double absD(double x){ if(x<0){ @@ -49,24 +50,3 @@ double powerD(double exp, double base){ return -1.0; } -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 x){ - double sum = 0.0; - for(int i = 0; i<=21; i++){ - sum += (1.0/fac(i)*(powerD(i,x))); - } - return sum; -} - diff --git a/src/exponent.h b/src/exponent.h index 9b53200..1264177 100644 --- a/src/exponent.h +++ b/src/exponent.h @@ -3,7 +3,6 @@ double p(double exp, double base); double powerD(double exp, double base); -double exponential(double x); double absD(double x); #endif // exponent.h \ No newline at end of file diff --git a/src/logarithmus.c b/src/logarithmus.c index 1c613e5..fa6ea62 100644 --- a/src/logarithmus.c +++ b/src/logarithmus.c @@ -3,6 +3,7 @@ #include "logarithmus.h" #include "exponent.h" +#include "reihen.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 cd80bc3..01fd0a5 100644 --- a/src/reihen.c +++ b/src/reihen.c @@ -4,4 +4,24 @@ #include "reihen.h" #include "exponent.h" -#include "logarithmus.h" \ No newline at end of file +#include "logarithmus.h" + +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 x){ + double sum = 0.0; + for(int i = 0; i<=21; i++){ + sum += (1.0/fac(i)*(powerD(i,x))); + } + return sum; +} \ No newline at end of file diff --git a/src/reihen.h b/src/reihen.h index bb17ea0..bd4e520 100644 --- a/src/reihen.h +++ b/src/reihen.h @@ -1,6 +1,6 @@ #ifndef REIHEN_H #define REIHEN_H - +double exponential(double x); #endif // reihen.h \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index ae49c01..d137507 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -4,6 +4,7 @@ #include "exponent.h" #include "logarithmus.h" +#include "reihen.h" void setUp(void) { @@ -101,26 +102,4 @@ void test_exponent_edge_case(void){ TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r5); } -void test_Exponent_with_positive_number(void){ - double r1, r2, r3; - - r1 = exponential(0.0); - r2 = exponential(1.0); - r3 = exponential(2.0); - - TEST_ASSERT_EQUAL_DOUBLE(1.0, r1); - TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2); - TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3); -} - -void test_Exponent_with_negative_number(void){ - double r1, r2, r3; - - r1 = exponential(-1.0); - r2 = exponential(-2.0); - - TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1); - TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2); -} - #endif // TEST \ No newline at end of file diff --git a/test/test_logarithmus.c b/test/test_logarithmus.c index 0f7aba1..7c24c13 100644 --- a/test/test_logarithmus.c +++ b/test/test_logarithmus.c @@ -4,6 +4,7 @@ #include "logarithmus.h" #include "exponent.h" +#include "reihen.h" void setUp(void) { diff --git a/test/test_reihen.c b/test/test_reihen.c index 043fc95..13d490c 100644 --- a/test/test_reihen.c +++ b/test/test_reihen.c @@ -14,4 +14,26 @@ void tearDown(void) { } +void test_Exponent_with_positive_number(void){ + double r1, r2, r3; + + r1 = exponential(0.0); + r2 = exponential(1.0); + r3 = exponential(2.0); + + TEST_ASSERT_EQUAL_DOUBLE(1.0, r1); + TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2); + TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3); +} + +void test_Exponent_with_negative_number(void){ + double r1, r2, r3; + + r1 = exponential(-1.0); + r2 = exponential(-2.0); + + TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1); + TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2); +} + #endif // TEST \ No newline at end of file