-
Notifications
You must be signed in to change notification settings - Fork 2
/
float.cpp
70 lines (57 loc) · 2.03 KB
/
float.cpp
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
#include "float.h"
#include "bool.h"
#include "assert.h"
value make$float_(double v) {
value ret;
ret.type = value::FLOAT;
ret.floatval = v;
return ret;
}
value __add__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$float_(x.floatval + y.floatval);
}
value __sub__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$float_(x.floatval - y.floatval);
}
value __mul__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$float_(x.floatval * y.floatval);
}
value __truediv__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$float_(x.floatval / y.floatval);
}
value __mod__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$float_(fmod(x.floatval, y.floatval));
}
value __eq__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval == y.floatval);
}
value __ne__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval != y.floatval);
}
value __lt__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval < y.floatval);
}
value __le__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval <= y.floatval);
}
value __ge__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval >= y.floatval);
}
value __gt__$float_$float_(value x, value y) {
assert(x.type == value::FLOAT && y.type == value::FLOAT);
return make$bool_(x.floatval > y.floatval);
}
value __bool__$float_(value self) {
assert(self.type == value::FLOAT);
return make$bool_(self.floatval != 0.0);
}