diff options
| author | Julian Weigt <juw@posteo.de> | 2025-12-28 11:20:32 +0000 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:55:48 +0100 |
| commit | 944f90c47ffcde862dfe5f258de0b1ebf229c20e (patch) | |
| tree | 0d4ef7dd8a8b97c440dc6abec538403c5726d0fd /ratio.c | |
| parent | e65748fa8908c46ae2e6af7ef63d28fb3427238d (diff) | |
Implement double arithmetic with error bounds.
Diffstat (limited to 'ratio.c')
| -rw-r--r-- | ratio.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; } |
