1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include "double.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
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; }
bool is_greater_certainly(double d1, double d2){ return (d1 > d2); }
bool is_greater_possibly(double d1, double d2){ return is_greater_certainly(d1,d2); }
double maximum(double d1, double d2){
if(d1>d2) return d1;
else return d2;
}
double product(double d1, double d2){ return d1*d2; }
double ratio(double d1, double d2){ return d1/d2; }
double absolute(double d){ return fabs(d); }
double power(double d, double p) { return pow(d,p); }
double valuetype_to_double(double d){ return d; }
int valuetype_to_string(char* s, double 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){ 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){
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){
if(exptype_is_infinite(p)) valuetype_to_latex(s,d);
else valuetype_to_latex(s,pow(d,1.0/p));
return 0;
}
|