diff --git a/src/exponent.c b/src/exponent.c index 00a5e39..6b82961 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -1,3 +1,5 @@ +#include + #include "exponent.h" int expI(unsigned int e, int num){ @@ -16,6 +18,8 @@ float expIN(int e, int num){ if(e>0){ return (float) expI(e, num); }else{ - return 1.0 / (float) expI(e, num); + printf("%d, %d\n", e, num); + printf("%f\n", 1.0 / (float) expI((e*-1), num)); + return (1.0 / (float) expI((e*-1), num)); } } \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index 02503f4..acfe8f1 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -24,5 +24,21 @@ void test_IntegerExponent_ForPositiveExponent(void){ TEST_ASSERT_EQUAL_INT(625, r3); } +void test_IntegerExponent_ForNegativeExponent(void){ + float r1, r2, r3; + + r1 = expIN(-1, 2); + r2 = expIN(-3, -3); + r3 = expIN(-2, -2); + + printf("Result 1: %d\n", r1); + printf("Result 2: %d\n", r2); + printf("Result 3: %d\n", r3); + + TEST_ASSERT_EQUAL_FLOAT(0.5, r1); + TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2); + TEST_ASSERT_EQUAL_FLOAT(0.25, r3); +} + #endif // TEST \ No newline at end of file