Browse Source

add logarithmic Function

remotes/origin/develop
Jonas Zitzmann 11 months ago
parent
commit
b34a590c54
  1. 18
      src/logarithmicFunctions.c
  2. 6
      src/logarithmicFunctions.h
  3. 18
      test/test_logarithmicFunctions.c

18
src/logarithmicFunctions.c

@ -0,0 +1,18 @@
#include "logarithmicFunctions.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double* logarithm_two_integer(int base, int num){
if(base <= 1 || num <= 0){
return NULL;
}
double* result = (double*)malloc(sizeof(double));
if (result == NULL) {
return NULL;
}
*result = log(num) / log(base);
return result;
}

6
src/logarithmicFunctions.h

@ -0,0 +1,6 @@
#ifndef THEADMIRALS_LOGARITHMICFUNCTIONS_H
#define THEADMIRALS_LOGARITHMICFUNCTIONS_H
double* logarithm_two_integer(int base, int num);
#endif //THEADMIRALS_LOGARITHMICFUNCTIONS_H

18
test/test_logarithmicFunctions.c

@ -0,0 +1,18 @@
#include "../src/logarithmicFunctions.h"
#include "unity.h"
#include "limits.h"
void setUp(void) {
// set stuff up here
}
void tearDown(void) {
// clean stuff up here
}
void test_logarithmicFunctions_logarithmiccalculation(void){
double expectedResult = 3.000000;
double* result;
result = logarithm_two_integer(2,8);
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result);
}
Loading…
Cancel
Save