diff --git a/src/exponent.c b/src/exponent.c index 37642e6..d9c7223 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -2,36 +2,22 @@ #include "exponent.h" -int expI(unsigned int e, int num){ - int prod = 1; - if(e==0){ +double expI(double e, double num){ + double prod = 1.0; + if(e==0.0){ return 1; }else{ - for(int i = 1; i <=e; i++){ + for(int i = 1; i <= (int) e; i++){ prod *= num; } return prod; } } -float expIN(int e, int num){ +double expIN(double e, double num){ if(e>0){ - return (float) expI(e, num); + return expI(e, num); }else{ - printf("%d, %d\n", e, num); - printf("%f\n", 1.0 / (float) expI((e*-1), num)); - return (1.0 / (float) expI((e*-1), num)); - } -} - -float expF(int e, float num){ - float prod = 1; - if(e==0){ - return 1; - }else{ - for(int i = 1; i <=e; i++){ - prod *= num; - } - return prod; + return (1.0 / expI((e*-1), num)); } } \ No newline at end of file diff --git a/src/exponent.h b/src/exponent.h index f7a030c..8f77ae2 100644 --- a/src/exponent.h +++ b/src/exponent.h @@ -1,8 +1,7 @@ #ifndef EXPONENT_H #define EXPONENT_H -int expI(unsigned int e, int num); -float expIN(int e, int num); -float expF(int e, float num); +double expI(double e, double num); +double expIN(double e, double num); #endif // exponent.h \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index acfe8f1..72bc9fc 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -12,24 +12,24 @@ void tearDown(void) { } -void test_IntegerExponent_ForPositiveExponent(void){ +void test_DoubleBase_ForPositiveExponent(void){ int r1, r2, r3; - r1 = expI(2, -2); - r2 = expI(3, -3); - r3 = expI(4, 5); + r1 = expI(2.0, -2.0); + r2 = expI(3.0, -3.0); + r3 = expI(4.0, 5.0); - TEST_ASSERT_EQUAL_INT(4, r1); - TEST_ASSERT_EQUAL_INT(-27, r2); - TEST_ASSERT_EQUAL_INT(625, r3); + TEST_ASSERT_EQUAL_INT(4.0, r1); + TEST_ASSERT_EQUAL_INT(-27.0, r2); + TEST_ASSERT_EQUAL_INT(625.0, r3); } -void test_IntegerExponent_ForNegativeExponent(void){ +void test_DoubleBase_ForNegativeExponent(void){ float r1, r2, r3; - r1 = expIN(-1, 2); - r2 = expIN(-3, -3); - r3 = expIN(-2, -2); + r1 = expIN(-1.0, 2.0); + r2 = expIN(-3.0, -3.0); + r3 = expIN(-2.0, -2.0); printf("Result 1: %d\n", r1); printf("Result 2: %d\n", r2);