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