forked from xomboverlord/xomb
/
ti_float.d
70 lines (57 loc) · 1.05 KB
/
ti_float.d
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
/*
* ti_float.d
*
* This module implements the TypeInfo for the float type.
*
*/
module dyndrt.typeinfos.ti_float;
class TypeInfo_f : TypeInfo {
char[] toString() {
return "float";
}
hash_t getHash(void *p) {
return *cast(uint *)p;
}
int equals(void *p1, void *p2) {
return _equals(*cast(float *)p1, *cast(float *)p2);
}
int compare(void *p1, void *p2) {
return _compare(*cast(float *)p1, *cast(float *)p2);
}
size_t tsize() {
return float.sizeof;
}
void swap(void *p1, void *p2) {
float t;
t = *cast(float *)p1;
*cast(float *)p1 = *cast(float *)p2;
*cast(float *)p2 = t;
}
void[] init() {
static float r;
return (cast(float *)&r)[0 .. 1];
}
package:
static int _equals(float f1, float f2) {
return f1 == f2 || (isnan(f1) && isnan(f2));
}
static int _compare(float d1, float d2) {
// if either are NaN
if (d1 !<>= d2) {
if (isnan(d1)) {
if (isnan(d2)) {
return 0;
}
return -1;
}
return 1;
}
if (d1 == d2) {
return 0;
}
else if (d1 < d2) {
return -1;
}
return 1;
}
}