summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Weigt <juw@posteo.de>2026-01-16 16:48:41 +0100
committerJulian Weigt <juw@posteo.de>2026-02-04 15:55:54 +0100
commiteefbfcdfc2f2374dcba95a62c31f3162e2247853 (patch)
tree8a2a2911c7c9d7f1a82f6e0943653daf14b15c02
parentfe85dc4e65d2aea155fbe201ff6378fcc9af0718 (diff)
Print all results when finished, make printing prettier.
-rw-r--r--charf.c13
-rw-r--r--double-error.c2
-rw-r--r--double-error.h2
-rw-r--r--double.c2
-rw-r--r--double.h2
-rw-r--r--ratio.c2
-rw-r--r--ratio.h3
7 files changed, 20 insertions, 6 deletions
diff --git a/charf.c b/charf.c
index e9b3ba7..b635391 100644
--- a/charf.c
+++ b/charf.c
@@ -171,7 +171,7 @@ void format_result(char* s, int index, int k, EXPTYPE p, VALUETYPE r){
for(int i=d; i<N; i++) l += sprintf(s+l," ");
char rts[128];
root_to_string(rts,r,p);
- l += sprintf(s+l,"%dth der.: %s",k,rts);
+ l += sprintf(s+l,"|f^(%d)|_1/%2.1f: %s",k,inv_exptype_to_double(p),rts);
}
bool over_threshold_charf(double t, int k){
@@ -256,7 +256,7 @@ void print_records(int num_exponents[K+1], EXPTYPE exponents[K+1][P], VALUETYPE
}
}
-typedef struct { int num_exponents[K+1]; EXPTYPE exponents[K+1][P]; VALUETYPE (*records_ratio)[K+1][P]; int (*records_index)[K+1][P]; int num_thread; int* domain_current; } Args;
+typedef struct { int num_exponents[K+1]; EXPTYPE exponents[K+1][P]; VALUETYPE (*records_ratio)[K+1][P]; int (*records_index)[K+1][P]; int num_thread; int* domain_current; int* cont; } Args;
/*Goes through all functions indexed by those numbers which equal the thread number module NUM_THREADS.*/
void* compute_chunk(void* arguments){
@@ -272,7 +272,9 @@ void* compute_chunk(void* arguments){
printf("Start considering length: %d\n",d);
}
i += NUM_THREADS;
- }
+ }
+ (*(args -> cont))++;
+ if(*(args -> cont) >= NUM_THREADS) printf("Calculation finished. Press any button to stop.\n");
}
int main() {
@@ -290,6 +292,7 @@ int main() {
for(int k=0; k<=K; k++) for(int p=0; p<num_exponents[k]; p++) records_ratio[k][p] = int_to_valuetype(0);
int domain_current = 0;
int result_code;
+ int cont = 0;
for (int i = 0; i < NUM_THREADS; i++) {
printf("In main: Creating thread %d.\n", i);
@@ -299,13 +302,13 @@ int main() {
args[i].records_index = &records_index;
args[i].num_thread = i;
args[i].domain_current = &domain_current;
+ args[i].cont = &cont;
result_code = pthread_create(&threads[i], NULL, compute_chunk, args+i);
}
size_t sz = 1024;
char prmpt[] = "To exit enter q, quit or exit.\nTo print current records to terminal enter r.\nTo print current records to a file enter p.\nTo do so with tex formatting enter t.\n";
char buff[sz];
- bool cont = true;
do {
getLine(prmpt, buff, sz);
if( 0 == strcmp(buff,"q") || 0 == strcmp(buff,"quit") || 0 == strcmp(buff,"exit") ){
@@ -313,7 +316,7 @@ int main() {
exit(EXIT_SUCCESS);
}
else if( 0 == strcmp(buff,"r")) print_records(num_exponents,exponents,records_ratio,records_index);
- } while(cont);
+ } while(cont < NUM_THREADS);
// wait for each thread to complete
for (int i = 0; i < NUM_THREADS; i++) {
diff --git a/double-error.c b/double-error.c
index 15fd4df..fa6db67 100644
--- a/double-error.c
+++ b/double-error.c
@@ -114,6 +114,8 @@ double_error power(double_error de, double_error p) {
double valuetype_to_double(double_error de){ return de.v; }
+double inv_exptype_to_double(double_error de){ return 1.0/de.v; }
+
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);
diff --git a/double-error.h b/double-error.h
index 2229685..f0b3e87 100644
--- a/double-error.h
+++ b/double-error.h
@@ -29,6 +29,8 @@ double_error power(double_error,double_error);
double valuetype_to_double(double_error);
+double inv_exptype_to_double(double_error);
+
int to_string(char*,double_error);
int root_to_string(char*,double_error,double_error);
diff --git a/double.c b/double.c
index 92d087d..b84b49a 100644
--- a/double.c
+++ b/double.c
@@ -31,6 +31,8 @@ double power(double d, double p) { return pow(d,p); }
double valuetype_to_double(double d){ return d; }
+double inv_exptype_to_double(double d){ return 1.0/d; }
+
int to_string(char* s, double d){
sprintf(s,"%f",d);
return 0;
diff --git a/double.h b/double.h
index 7b23791..707e1e6 100644
--- a/double.h
+++ b/double.h
@@ -27,6 +27,8 @@ double power(double,double);
double valuetype_to_double(double);
+double inv_exptype_to_double(double);
+
int to_string(char*,double);
int root_to_string(char*,double,double);
diff --git a/ratio.c b/ratio.c
index eea0b9a..92e39d8 100644
--- a/ratio.c
+++ b/ratio.c
@@ -129,6 +129,8 @@ rational power(rational r, unsigned int p){
return s;
}
+double inv_exptype_to_double(int r){ return 1.0/((double)r); }
+
double valuetype_to_double(rational r){
double i;
if(r.s) { i=-1.0; } else { i=1.0; }
diff --git a/ratio.h b/ratio.h
index e555cfb..884681d 100644
--- a/ratio.h
+++ b/ratio.h
@@ -27,9 +27,10 @@ rational absolute(rational);
rational power(rational,unsigned int);
-
double valuetype_to_double(rational);
+double inv_exptype_to_double(int);
+
int to_string(char*,rational r);
int root_to_string(char*,rational r,unsigned int);