summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Weigt <juw@posteo.de>2026-01-16 13:41:52 +0100
committerJulian Weigt <juw@posteo.de>2026-02-04 15:55:53 +0100
commit8145ba753df183f0d48cd6e9cc5a01b215eb31dc (patch)
tree6ab91cd3774bb42d55c196db26387f67bf082da3
parent5c0dc646b78e2d7ef25088ac78397e2ed613cba1 (diff)
Properly use header files and change return type for conversion from bool to int.
-rw-r--r--charf.c3
-rw-r--r--double-error.c8
-rw-r--r--double-error.h9
-rw-r--r--double.c9
-rw-r--r--double.h9
-rw-r--r--misc.c4
-rw-r--r--misc.h4
-rw-r--r--ratio.c8
-rw-r--r--ratio.h9
9 files changed, 42 insertions, 21 deletions
diff --git a/charf.c b/charf.c
index 266ed5a..7f4f2af 100644
--- a/charf.c
+++ b/charf.c
@@ -1,9 +1,10 @@
-#include <stdio.h>
#include <stdlib.h>
+#include <stdio.h>
#include <math.h>
//for multithreading
#include <pthread.h>
#include <stdbool.h>
+#include <string.h>
//getLine
#include "misc.h"
diff --git a/double-error.c b/double-error.c
index 1ab0aec..4655f7c 100644
--- a/double-error.c
+++ b/double-error.c
@@ -22,9 +22,9 @@ double_error int_to_exptype(double d){
return de;
}
-bool to_string(char* s, double_error de){
+int to_string(char* s, double_error de){
sprintf(s,"%f… +/- %6.1e",de.v,de.e);
- return true;
+ return 0;
}
double_error sum(double_error de1, double_error de2){
@@ -114,8 +114,8 @@ double_error power(double_error de, double_error p) {
double to_double(double_error de){ return de.v; }
-bool root_to_string(char* s, double_error de, double_error p){
+int root_to_string(char* s, double_error de, double_error p){
double_error de1p = power(de,ratio(int_to_valuetype(1),p));
to_string(s,de1p);
- return true;
+ return 0;
}
diff --git a/double-error.h b/double-error.h
index 27894c3..719b8c6 100644
--- a/double-error.h
+++ b/double-error.h
@@ -1,3 +1,6 @@
+#ifndef DOUBLE_ERROR_H
+#define DOUBLE_ERROR_H
+
#include <stdbool.h>
typedef struct {double v; double e;} double_error;
@@ -26,6 +29,8 @@ double_error power(double_error,double_error);
double to_double(double_error);
-bool to_string(char*,double_error);
+int to_string(char*,double_error);
+
+int root_to_string(char*,double_error,double_error);
-bool root_to_string(char*,double_error,double_error);
+#endif
diff --git a/double.c b/double.c
index 1ad289f..9081ebb 100644
--- a/double.c
+++ b/double.c
@@ -1,3 +1,4 @@
+#include "double.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
@@ -30,12 +31,12 @@ double power(double d, double p) { return pow(d,p); }
double to_double(double d){ return d; }
-bool to_string(char* s, double d){
+int to_string(char* s, double d){
sprintf(s,"%f",d);
- return true;
+ return 0;
}
-bool root_to_string(char* s, double d, double p){
+int root_to_string(char* s, double d, double p){
to_string(s,pow(d,1/p));
- return true;
+ return 0;
}
diff --git a/double.h b/double.h
index 0c42b04..077b4b8 100644
--- a/double.h
+++ b/double.h
@@ -1,3 +1,6 @@
+#ifndef DOUBLE_H
+#define DOUBLE_H
+
#include <stdbool.h>
double int_to_valuetype(int);
@@ -24,6 +27,8 @@ double power(double,double);
double to_double(double);
-double to_string(char*,double);
+int to_string(char*,double);
+
+int root_to_string(char*,double,double);
-double root_to_string(char*,double,double);
+#endif
diff --git a/misc.c b/misc.c
index 9de0044..df95051 100644
--- a/misc.c
+++ b/misc.c
@@ -1,11 +1,13 @@
+#include "misc.h"
//for reading from stdin
#include <string.h>
+#include <stdio.h>
#define OK 0
#define NO_INPUT 1
#define TOO_LONG 2
-static int getLine (char *prmpt, char *buff, size_t sz) {
+int getLine (char *prmpt, char *buff, size_t sz) {
int ch, extra;
// Get line with buffer overrun protection.
diff --git a/misc.h b/misc.h
index 627136f..6358051 100644
--- a/misc.h
+++ b/misc.h
@@ -1 +1,3 @@
-static int getLine (char *prmpt, char *buff, size_t sz);
+#include<string.h>
+
+int getLine(char*, char*, size_t);
diff --git a/ratio.c b/ratio.c
index 3bb5ef3..bf428ec 100644
--- a/ratio.c
+++ b/ratio.c
@@ -135,14 +135,14 @@ double to_double(rational r){
return i*((double)r.n)/((double)r.d);
}
-bool to_string(char* s, rational r){
+int to_string(char* s, rational r){
double f = to_double(r);
sprintf(s,"%llu / %llu = %f… +/- %6.1e",r.n,r.d,f,f*DBL_EPSILON);
- return true;
+ return 0;
}
-bool root_to_string(char* s, rational r, unsigned int p){
+int root_to_string(char* s, rational r, unsigned int p){
double f = pow(to_double(r),1.0/p);
sprintf(s,"(%llu / %llu)^1/%i = %f… +/- %6.1e",r.n,r.d,p,f,2*DBL_EPSILON*f);
- return true;
+ return 0;
}
diff --git a/ratio.h b/ratio.h
index ff4015e..e273f7f 100644
--- a/ratio.h
+++ b/ratio.h
@@ -1,3 +1,6 @@
+#ifndef RATIO_H
+#define RATIO_H
+
#include <stdbool.h>
typedef struct {bool s; unsigned long long n; unsigned long long d;} rational;
@@ -27,6 +30,8 @@ rational power(rational,unsigned int);
double to_double(rational);
-bool to_string(char*,rational r);
+int to_string(char*,rational r);
+
+int root_to_string(char*,rational r,unsigned int);
-bool root_to_string(char*,rational r,unsigned int);
+#endif