comparison lphobos/typeinfo1/ti_double.d @ 58:2c3cd3596187 trunk

[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum Added initial support for CatExp aka 'a ~ b' Fixed global constant static arrays initialized with string literals Fixed casting any dynamic array to void* Fixed new expression with temporary storage Fixed alias declarations in function scope Fixed relational comparisons of pointers
author lindquist
date Thu, 25 Oct 2007 09:02:55 +0200
parents lphobos/typeinfo/ti_double.d@06ccc817acd4
children
comparison
equal deleted inserted replaced
57:a9d29e9f1fed 58:2c3cd3596187
1
2 // double
3
4 module typeinfo1.ti_double;
5
6 class TypeInfo_d : TypeInfo
7 {
8 char[] toString() { return "double"; }
9
10 hash_t getHash(void *p)
11 {
12 return (cast(uint *)p)[0] + (cast(uint *)p)[1];
13 }
14
15 static bool _isnan(double d)
16 {
17 return d !<>= 0;
18 }
19
20 static int _equals(double f1, double f2)
21 {
22 return f1 == f2 ||
23 (_isnan(f1) && _isnan(f2));
24 }
25
26 static int _compare(double d1, double 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(double *)p1, *cast(double *)p2);
43 }
44
45 int compare(void *p1, void *p2)
46 {
47 return _compare(*cast(double *)p1, *cast(double *)p2);
48 }
49
50 size_t tsize()
51 {
52 return double.sizeof;
53 }
54
55 void swap(void *p1, void *p2)
56 {
57 double t;
58
59 t = *cast(double *)p1;
60 *cast(double *)p1 = *cast(double *)p2;
61 *cast(double *)p2 = t;
62 }
63
64 void[] init()
65 { static double r;
66
67 return (&r)[0 .. 1];
68 }
69 }
70