summaryrefslogtreecommitdiff
path: root/ratio.c
diff options
context:
space:
mode:
Diffstat (limited to 'ratio.c')
-rw-r--r--ratio.c8
1 files changed, 7 insertions, 1 deletions
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;
+}