Browse Source

refactoring: move helper functions to util.c

master
fdai7848 12 months ago
parent
commit
7bfc5a1fce
  1. 8
      src/exponent.c
  2. 1
      src/logarithmus.c
  3. 17
      src/reihen.c
  4. 28
      src/util.c
  5. 8
      src/util.h
  6. 1
      test/test_exponent.c
  7. 1
      test/test_logarithmus.c
  8. 1
      test/test_reihen.c

8
src/exponent.c

@ -5,13 +5,7 @@
#include "exponent.h"
#include "logarithmus.h"
#include "reihen.h"
double absD(double x){
if(x<0){
return -1 * x;
}
return x;
}
#include "util.h"
double p(double exp, double base){
double prod = 1.0;

1
src/logarithmus.c

@ -4,6 +4,7 @@
#include "logarithmus.h"
#include "exponent.h"
#include "reihen.h"
#include "util.h"
double logX(double base, double value){
if(base == 1.0 || base <= 0.0 || value <= 0.0){

17
src/reihen.c

@ -5,21 +5,10 @@
#include "reihen.h"
#include "exponent.h"
#include "logarithmus.h"
#include "util.h"
#define PI pi(1e-8)
unsigned long long fac(int x){
unsigned long long prod = 1;
if(x==0) return 1;
for (int i = 1; i <= x; i++){
if (prod > ULLONG_MAX / i){
break;
}
prod*=i;
}
return prod;
}
double exponential(double exp){
double sum = 0.0;
for(int i = 0; i<=21; i++){
@ -32,10 +21,6 @@ double euler(){
return exponential(1);
}
double squashDegreesTo360(double degrees){
int multiple = degrees / 360;
return degrees - (360*multiple);
}
double radians(double degrees){
return degrees * PI / 180;

28
src/util.c

@ -0,0 +1,28 @@
#include <stdio.h>
#include <limits.h>
#include "util.h"
double absD(double x){
if(x<0){
return -1 * x;
}
return x;
}
double squashDegreesTo360(double degrees){
int multiple = degrees / 360;
return degrees - (360*multiple);
}
unsigned long long fac(int x){
unsigned long long prod = 1;
if(x==0) return 1;
for (int i = 1; i <= x; i++){
if (prod > ULLONG_MAX / i){
break;
}
prod*=i;
}
return prod;
}

8
src/util.h

@ -0,0 +1,8 @@
#ifndef UTIL_H
#define UTIL_H
double absD(double x);
double squashDegreesTo360(double degrees);
unsigned long long fac(int x);
#endif // util.h

1
test/test_exponent.c

@ -5,6 +5,7 @@
#include "exponent.h"
#include "logarithmus.h"
#include "reihen.h"
#include "util.h"
void setUp(void)
{

1
test/test_logarithmus.c

@ -5,6 +5,7 @@
#include "logarithmus.h"
#include "exponent.h"
#include "reihen.h"
#include "util.h"
void setUp(void)
{

1
test/test_reihen.c

@ -5,6 +5,7 @@
#include "reihen.h"
#include "exponent.h"
#include "logarithmus.h"
#include "util.h"
void setUp(void)
{

Loading…
Cancel
Save