summaryrefslogtreecommitdiff
path: root/ratio.c
diff options
context:
space:
mode:
authorJulian Weigt <juw@posteo.de>2025-12-28 11:20:32 +0000
committerJulian Weigt <juw@posteo.de>2026-02-04 15:55:48 +0100
commit944f90c47ffcde862dfe5f258de0b1ebf229c20e (patch)
tree0d4ef7dd8a8b97c440dc6abec538403c5726d0fd /ratio.c
parente65748fa8908c46ae2e6af7ef63d28fb3427238d (diff)
Implement double arithmetic with error bounds.
Diffstat (limited to 'ratio.c')
-rw-r--r--ratio.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ratio.c b/ratio.c
index 8f86f93..384f944 100644
--- a/ratio.c
+++ b/ratio.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <math.h>
#include <limits.h>
+#include <float.h>
typedef unsigned long long num;
@@ -35,6 +36,8 @@ rational convert_int(int i){
return r;
}
+unsigned int to_exptype(unsigned int i){ return i; }
+
num gcd(num a, num b){
num c;
while (b) {
@@ -120,6 +123,7 @@ double to_double(rational r){
}
bool to_string(char* s,rational r){
- sprintf(s,"%llu / %llu",r.n,r.d);
+ double f = to_double(r);
+ sprintf(s,"%llu / %llu = %f +- %.24f",r.n,r.d,f,f*DBL_EPSILON);
return true;
}