diff options
| -rw-r--r-- | charf.c | 3 | ||||
| -rw-r--r-- | double-error.c | 8 | ||||
| -rw-r--r-- | double-error.h | 9 | ||||
| -rw-r--r-- | double.c | 9 | ||||
| -rw-r--r-- | double.h | 9 | ||||
| -rw-r--r-- | misc.c | 4 | ||||
| -rw-r--r-- | misc.h | 4 | ||||
| -rw-r--r-- | ratio.c | 8 | ||||
| -rw-r--r-- | ratio.h | 9 |
9 files changed, 42 insertions, 21 deletions
@@ -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 @@ -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; } @@ -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 @@ -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. @@ -1 +1,3 @@ -static int getLine (char *prmpt, char *buff, size_t sz); +#include<string.h> + +int getLine(char*, char*, size_t); @@ -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; } @@ -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 |
