From 8e416217472864cc1cc9abbbedf095fe29597e79 Mon Sep 17 00:00:00 2001 From: fdai7848 Date: Mon, 29 Jan 2024 17:43:37 +0100 Subject: [PATCH] Add check for integer exponent --- src/exponent.c | 12 ++++++++---- test/test_exponent.c | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/exponent.c b/src/exponent.c index d9c7223..3f4895a 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -15,9 +15,13 @@ double expI(double e, double num){ } double expIN(double e, double num){ - if(e>0){ - return expI(e, num); - }else{ - return (1.0 / expI((e*-1), num)); + if(e - ((int) e) < 0.0001 || e - ((int) e) > -0.0001){ + if(e>0){ + return expI(e, num); + } + else{ + return (1.0 / expI((e*-1), num)); + } } + return 0; } \ No newline at end of file diff --git a/test/test_exponent.c b/test/test_exponent.c index 72bc9fc..c9262dc 100644 --- a/test/test_exponent.c +++ b/test/test_exponent.c @@ -31,9 +31,9 @@ void test_DoubleBase_ForNegativeExponent(void){ r2 = expIN(-3.0, -3.0); r3 = expIN(-2.0, -2.0); - printf("Result 1: %d\n", r1); - printf("Result 2: %d\n", r2); - printf("Result 3: %d\n", r3); + printf("Result 1: %f\n", r1); + printf("Result 2: %f\n", r2); + printf("Result 3: %f\n", r3); TEST_ASSERT_EQUAL_FLOAT(0.5, r1); TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2);