From b34a590c548aac53f2c269b482bc64cdedfe7ed3 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:31:18 +0100 Subject: [PATCH] add logarithmic Function --- src/logarithmicFunctions.c | 18 ++++++++++++++++++ src/logarithmicFunctions.h | 6 ++++++ test/test_logarithmicFunctions.c | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/logarithmicFunctions.c create mode 100644 src/logarithmicFunctions.h create mode 100644 test/test_logarithmicFunctions.c diff --git a/src/logarithmicFunctions.c b/src/logarithmicFunctions.c new file mode 100644 index 0000000..e940cb5 --- /dev/null +++ b/src/logarithmicFunctions.c @@ -0,0 +1,18 @@ +#include "logarithmicFunctions.h" +#include +#include +#include + +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; +} diff --git a/src/logarithmicFunctions.h b/src/logarithmicFunctions.h new file mode 100644 index 0000000..c13f29d --- /dev/null +++ b/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 diff --git a/test/test_logarithmicFunctions.c b/test/test_logarithmicFunctions.c new file mode 100644 index 0000000..512696e --- /dev/null +++ b/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); +} \ No newline at end of file