diff options
| author | Julian Weigt <juw@posteo.de> | 2025-12-28 15:40:34 +0000 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:55:49 +0100 |
| commit | 3cff2acc8eec95183fe4cd3dcc3a3bf30b37ce66 (patch) | |
| tree | d2f3627b2d6c1a0a65c3713ab9bb687ea2c1d1b0 | |
| parent | 634f01454f1c0f1a33adc50b5f584e39748ff832 (diff) | |
Add root_to_string function to enable printing of roots.
| -rw-r--r-- | charf.c | 5 | ||||
| -rw-r--r-- | double-error.c | 6 | ||||
| -rw-r--r-- | double-error.h | 2 | ||||
| -rw-r--r-- | double.c | 5 | ||||
| -rw-r--r-- | double.h | 2 | ||||
| -rw-r--r-- | ratio.c | 8 | ||||
| -rw-r--r-- | ratio.h | 2 |
7 files changed, 27 insertions, 3 deletions
@@ -177,13 +177,14 @@ void compute(EXPTYPE p, int t){ /*Print f and ||Mf^{(k)}||_p/||f^{(k)}||_p if the latter is close to 1/2.*/ //if(to_double(r)>.4997) if(to_double(r)>.65) + //if(to_double(r)>.30) { printf("f: "); for(int i=0;i<D;i++) printf("%1.0f ",to_double(f[i])); printf("\n"); char s[128]; - to_string(s,r); - printf("%.4f (%s)\n",to_double(r),s); + root_to_string(s,r,p); + printf("%s\n",s); } } diff --git a/double-error.c b/double-error.c index 06d27ae..d5bac3d 100644 --- a/double-error.c +++ b/double-error.c @@ -108,3 +108,9 @@ 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){ + double_error de1p = power(de,ratio(convert_int(1),p)); + to_string(s,de1p); + return true; +} diff --git a/double-error.h b/double-error.h index bce8cd5..23b78d9 100644 --- a/double-error.h +++ b/double-error.h @@ -23,3 +23,5 @@ double_error power(double_error,double_error); double to_double(double_error); bool to_string(char*,double_error); + +bool root_to_string(char*,double_error,double_error); @@ -31,3 +31,8 @@ bool to_string(char* s, double d){ sprintf(s,"%f",d); return true; } + +bool root_to_string(char* s, double d, double p){ + to_string(s,pow(d,1/p)); + return true; +} @@ -21,3 +21,5 @@ double power(double,double); double to_double(double); double to_string(char*,double); + +double root_to_string(char*,double,double); @@ -127,8 +127,14 @@ double to_double(rational r){ return i*((double)r.n)/((double)r.d); } -bool to_string(char* s,rational r){ +bool 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; } + +bool 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; +} @@ -28,3 +28,5 @@ rational power(rational,unsigned int); double to_double(rational); bool to_string(char*,rational r); + +bool root_to_string(char*,rational r,unsigned int); |
