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 /ratio.c | |
| parent | 634f01454f1c0f1a33adc50b5f584e39748ff832 (diff) | |
Add root_to_string function to enable printing of roots.
Diffstat (limited to 'ratio.c')
| -rw-r--r-- | ratio.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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; +} |
