From 3cff2acc8eec95183fe4cd3dcc3a3bf30b37ce66 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Sun, 28 Dec 2025 15:40:34 +0000 Subject: Add root_to_string function to enable printing of roots. --- ratio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ratio.c') diff --git a/ratio.c b/ratio.c index 07a28ce..3b38ea7 100644 --- a/ratio.c +++ b/ratio.c @@ -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; +} -- cgit v1.2.3