diff options
| author | Julian Weigt <juw@posteo.de> | 2026-01-18 13:28:25 +0100 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:56:45 +0100 |
| commit | b7835be8db1d6d2ef60bbe9e972cb708c0fee8c0 (patch) | |
| tree | 8d81ca6a69e2fd10762f9fb60b660cd958ff0efc /double.c | |
| parent | 6ceb2c20056d6cece59791686deeeac312fa6009 (diff) | |
Allow p=∞ in program and adjust and generalize printing accordingly.
Diffstat (limited to 'double.c')
| -rw-r--r-- | double.c | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -8,6 +8,10 @@ double int_to_valuetype(int i){ return (double) i; } double int_to_exptype(double d){ return d; } +double infinity_to_exptype(){ return INFINITY; } + +bool exptype_is_infinite(double d){ return d==INFINITY; } + double sum(double d1, double d2){ return d1+d2; } double difference(double d1, double d2){ return d1-d2; } @@ -31,26 +35,38 @@ double power(double d, double p) { return pow(d,p); } double valuetype_to_double(double d){ return d; } -double exptype_to_double(double d){ return d; } - int valuetype_to_string(char* s, double d){ - sprintf(s,"%f",d); + if( d == 0.0 || d == 1.0 || d == 2.0 || d == 4.0 || d == 8.0 || d == 16.0 ) sprintf(s,"%d", (int)d); + else sprintf(s,"%4.3f",d); return 0; } -int valuetype_to_latex(char* s, double d){ - if( d == 0.0) sprintf(s,"$0$"); - else if( d == 1.0) sprintf(s,"$1$"); - else sprintf(s,"$%4.3f$",d); - return 0; +int valuetype_to_latex(char* s, double d){ return valuetype_to_string(s,d); } + +int exptype_to_string(char *s, double p){ + if(exptype_is_infinite(p)){ + sprintf(s,"inf"); + return 0; + } + else return valuetype_to_string(s,p); +} + +int exptype_to_latex(char *s, double p){ + if(exptype_is_infinite(p)){ + sprintf(s,"\\infty"); + return 0; + } + else return valuetype_to_latex(s,p); } int root_to_string(char* s, double d, double p){ - valuetype_to_string(s,pow(d,1.0/p)); + if(exptype_is_infinite(p)) valuetype_to_string(s,d); + else valuetype_to_string(s,pow(d,1.0/p)); return 0; } int root_to_latex(char* s, double d, double p){ - valuetype_to_latex(s,pow(d,1.0/p)); + if(exptype_is_infinite(p)) valuetype_to_latex(s,d); + else valuetype_to_latex(s,pow(d,1.0/p)); return 0; } |
