diff --git a/src/exponent.c b/src/exponent.c index b1135fd..2cfecf5 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -42,8 +42,8 @@ unsigned long long fac(int x){ double exponential(double x){ double sum = 0.0; - for(int i = 1; i<=21; i++){ - sum += (1/fac(i)*(expIN(i,x))); + for(int i = 0; i<=21; i++){ + sum += (1.0/fac(i)*(expIN(i,x))); } return sum; } \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index c9262dc..6d53ef1 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -40,5 +40,22 @@ void test_DoubleBase_ForNegativeExponent(void){ TEST_ASSERT_EQUAL_FLOAT(0.25, r3); } +void test_Exponent_with_positive_number(void){ + double r1, r2, r3; + + r1 = exponential(0.0); + r2 = exponential(1.0); + r3 = exponential(2.0); + + printf("Result 1: %8.lf\n", r1); + printf("Result 2: %lf\n", r2); + printf("Result 3: %lf\n", r3); + + 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); +} + + #endif // TEST \ No newline at end of file