1 
2 // float
3 
4 module rt.compiler.dmd.typeinfo.ti_float;
5 
6 class TypeInfo_f : TypeInfo
7 {
8     override char[] toString() { return "float"; }
9 
10     override hash_t getHash(in void* p)
11     {
12         return cast(hash_t)(*cast(uint *)p);
13     }
14 
15     static equals_t _equals(float f1, float f2)
16     {
17         return f1 == f2 ||
18                 (f1 !<>= f1 && f2 !<>= f2);
19     }
20 
21     static int _compare(float d1, float d2)
22     {
23         if (d1 !<>= d2)         // if either are NaN
24         {
25             if (d1 !<>= d1)
26             {   if (d2 !<>= d2)
27                     return 0;
28                 return -1;
29             }
30             return 1;
31         }
32         return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
33     }
34 
35     override equals_t equals(in void* p1, in void* p2)
36     {
37         return _equals(*cast(float *)p1, *cast(float *)p2);
38     }
39 
40     override int compare(in void* p1, in void* p2)
41     {
42         return _compare(*cast(float *)p1, *cast(float *)p2);
43     }
44 
45     override size_t talign()
46     {
47         return float.alignof;
48     }
49 
50     override size_t tsize()
51     {
52         return float.sizeof;
53     }
54 
55     override void swap(void *p1, void *p2)
56     {
57         float t;
58 
59         t = *cast(float *)p1;
60         *cast(float *)p1 = *cast(float *)p2;
61         *cast(float *)p2 = t;
62     }
63 
64     override void[] init()
65     {   static float r;
66 
67         return (cast(float *)&r)[0 .. 1];
68     }
69 }