comparison lphobos/typeinfo/ti_real.d @ 53:06ccc817acd4 trunk

[svn r57] Added most basic TypeInfo (rebuild lphobos). Fixed some SymOffExp bugs. Added another typeinfo test case.
author lindquist
date Tue, 23 Oct 2007 07:16:02 +0200
parents
children
comparison
equal deleted inserted replaced
52:0c77619e803b 53:06ccc817acd4
1
2 // real
3
4 module typeinfo.ti_real;
5
6 class TypeInfo_e : TypeInfo
7 {
8 char[] toString() { return "real"; }
9
10 hash_t getHash(void *p)
11 {
12 return (cast(uint *)p)[0] + (cast(uint *)p)[1] + (cast(ushort *)p)[4];
13 }
14
15 static bool _isnan(real r)
16 {
17 return r !<>= 0;
18 }
19
20 static int _equals(real f1, real f2)
21 {
22 return f1 == f2 ||
23 (_isnan(f1) && _isnan(f2));
24 }
25
26 static int _compare(real d1, real d2)
27 {
28 if (d1 !<>= d2) // if either are NaN
29 {
30 if (_isnan(d1))
31 { if (_isnan(d2))
32 return 0;
33 return -1;
34 }
35 return 1;
36 }
37 return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
38 }
39
40 int equals(void *p1, void *p2)
41 {
42 return _equals(*cast(real *)p1, *cast(real *)p2);
43 }
44
45 int compare(void *p1, void *p2)
46 {
47 return _compare(*cast(real *)p1, *cast(real *)p2);
48 }
49
50 size_t tsize()
51 {
52 return real.sizeof;
53 }
54
55 void swap(void *p1, void *p2)
56 {
57 real t;
58
59 t = *cast(real *)p1;
60 *cast(real *)p1 = *cast(real *)p2;
61 *cast(real *)p2 = t;
62 }
63
64 void[] init()
65 { static real r;
66
67 return (&r)[0 .. 1];
68 }
69 }
70