diff options
| author | Julian Weigt <juw@posteo.de> | 2026-01-16 19:05:23 +0100 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:55:54 +0100 |
| commit | 2d7d2f09189d57b47863d2ce89b6a450f4402681 (patch) | |
| tree | e8ac8b38fe3125631d4e6f1be0c068b4600a5b1e /ratio.c | |
| parent | eefbfcdfc2f2374dcba95a62c31f3162e2247853 (diff) | |
Finish all printing including latex and niceties for printing 0 and 1 and such.
Diffstat (limited to 'ratio.c')
| -rw-r--r-- | ratio.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -137,14 +137,35 @@ double valuetype_to_double(rational r){ return i*((double)r.n)/((double)r.d); } -int to_string(char* s, rational r){ +int valuetype_to_string(char* s, rational r){ double f = valuetype_to_double(r); sprintf(s,"%llu / %llu = %f… +/- %6.1e",r.n,r.d,f,f*DBL_EPSILON); return 0; } +int valuetype_to_latex(char* s, rational r){ + if(r.d == 1) { + if(r.n == 0) sprintf(s,"$0$"); + else if(r.s) sprintf(s,"$-%lld$",r.n); + else if(!r.s) sprintf(s,"$%lld$",r.n); + } + else{ + double f = valuetype_to_double(r); + sprintf(s,"$\\frac{%llu}{%llu} = %4.3f\\ldots$",r.n,r.d,f); + //sprintf(s,"$\\frac{%llu}{%llu} = %3.2f\\ldots \\pm %1.0e$",r.n,r.d,f,f*DBL_EPSILON); + } + return 0; +} + int root_to_string(char* s, rational r, unsigned int p){ double f = pow(valuetype_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 0; } + +int root_to_latex(char* s, rational r, unsigned int p){ + double f = pow(valuetype_to_double(r),1.0/p); + sprintf(s,"$\\bigl(\\frac{%llu}{%llu}\\bigr)^{\\frac1{%i}} = %4.3f\\ldots$",r.n,r.d,p,f); + //sprintf(s,"$\\bigl(\\frac{%llu}{%llu}\\bigr)^{\\frac1{%i}} = %3.2f\\ldots \\pm %1.0e$",r.n,r.d,p,f,2*DBL_EPSILON*f); + return 0; +} |
