summaryrefslogtreecommitdiff
path: root/double.c
diff options
context:
space:
mode:
Diffstat (limited to 'double.c')
-rw-r--r--double.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/double.c b/double.c
index 09fcc28..0799e7d 100644
--- a/double.c
+++ b/double.c
@@ -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;
}