Browse Source

refactoring: change function names and parameter names in logarithmus.c

master
fdai7848 11 months ago
parent
commit
923b1fe04c
  1. 3
      src/exponent.c
  2. 14
      src/logarithmus.c
  3. 4
      src/logarithmus.h
  4. 24
      test/test_logarithmus.c

3
src/exponent.c

@ -64,10 +64,9 @@ unsigned long long fac(int x){
double exponential(double x){
double sum = 0.0;
for(int i = 0; i<=20; i++){
for(int i = 0; i<=21; i++){
sum += (1.0/fac(i)*(powerD(i,x)));
}
return sum;
}

14
src/logarithmus.c

@ -4,19 +4,19 @@
#include "logarithmus.h"
#include "exponent.h"
double logX(double b, double a){
if(b == 1.0 || b <= 0.0 || a <= 0.0){
double logX(double base, double value){
if(base == 1.0 || base <= 0.0 || value <= 0.0){
return -1.0;
}
return(logN(a, 0.00000001)/logN(b, 0.00000001));
return(logN(value, 0.00000001)/logN(base, 0.00000001));
}
double logDec(double a){
return logX(10.0, a);
double log10(double value){
return logX(10.0, value);
}
double logBin(double a){
return logX(2.0, a);
double log2(double value){
return logX(2.0, value);
}
double logN(double x, double eps){

4
src/logarithmus.h

@ -3,7 +3,7 @@
double logN(double x, double eps);
double logX(double b, double a);
double logDec(double a);
double logBin(double a);
double log10(double a);
double log2(double a);
#endif // logarithmus.h

24
test/test_logarithmus.c

@ -82,12 +82,12 @@ void test_logarithmic_function_with_decimals(void){
void test_logarithmic_function_to_base_10(void){
double r1, r2, r3, r4, r5, r6;
r1 = logDec(100.0);
r2 = logDec(100.6479);
r3 = logDec(10.587);
r4 = logDec(4.341);
r5 = logDec(0.34979);
r6 = logDec(1.0);
r1 = log10(100.0);
r2 = log10(100.6479);
r3 = log10(10.587);
r4 = log10(4.341);
r5 = log10(0.34979);
r6 = log10(1.0);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.002804, r2);
@ -100,12 +100,12 @@ void test_logarithmic_function_to_base_10(void){
void test_logarithmic_function_to_base_2(void){
double r1, r2, r3, r4, r5, r6;
r1 = logBin(1024.0);
r2 = logBin(1024.8742);
r3 = logBin(900.587);
r4 = logBin(78.341);
r5 = logBin(0.34979);
r6 = logBin(1.0);
r1 = log2(1024.0);
r2 = log2(1024.8742);
r3 = log2(900.587);
r4 = log2(78.341);
r5 = log2(0.34979);
r6 = log2(1.0);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 10.0, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 10.001231, r2);

Loading…
Cancel
Save