Browse Source

Add check for integer exponent

master
fdai7848 11 months ago
parent
commit
8e41621747
  1. 6
      src/exponent.c
  2. 6
      test/test_exponent.c

6
src/exponent.c

@ -15,9 +15,13 @@ double expI(double e, double num){
}
double expIN(double e, double num){
if(e - ((int) e) < 0.0001 || e - ((int) e) > -0.0001){
if(e>0){
return expI(e, num);
}else{
}
else{
return (1.0 / expI((e*-1), num));
}
}
return 0;
}

6
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);

Loading…
Cancel
Save