Mercurial > projects > ldc
comparison lphobos/std/typeinfounsupported/ti_double.d @ 1:c53b6e3fe49a trunk
[svn r5] Initial commit. Most things are very rough.
author | lindquist |
---|---|
date | Sat, 01 Sep 2007 21:43:27 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:a9e71648e74d | 1:c53b6e3fe49a |
---|---|
1 | |
2 // double | |
3 | |
4 module std.typeinfo.ti_double; | |
5 | |
6 private import std.math; | |
7 | |
8 class TypeInfo_d : TypeInfo | |
9 { | |
10 char[] toString() { return "double"; } | |
11 | |
12 hash_t getHash(void *p) | |
13 { | |
14 return (cast(uint *)p)[0] + (cast(uint *)p)[1]; | |
15 } | |
16 | |
17 static int _equals(double f1, double f2) | |
18 { | |
19 return f1 == f2 || | |
20 (isnan(f1) && isnan(f2)); | |
21 } | |
22 | |
23 static int _compare(double d1, double d2) | |
24 { | |
25 if (d1 !<>= d2) // if either are NaN | |
26 { | |
27 if (isnan(d1)) | |
28 { if (isnan(d2)) | |
29 return 0; | |
30 return -1; | |
31 } | |
32 return 1; | |
33 } | |
34 return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); | |
35 } | |
36 | |
37 int equals(void *p1, void *p2) | |
38 { | |
39 return _equals(*cast(double *)p1, *cast(double *)p2); | |
40 } | |
41 | |
42 int compare(void *p1, void *p2) | |
43 { | |
44 return _compare(*cast(double *)p1, *cast(double *)p2); | |
45 } | |
46 | |
47 size_t tsize() | |
48 { | |
49 return double.sizeof; | |
50 } | |
51 | |
52 void swap(void *p1, void *p2) | |
53 { | |
54 double t; | |
55 | |
56 t = *cast(double *)p1; | |
57 *cast(double *)p1 = *cast(double *)p2; | |
58 *cast(double *)p2 = t; | |
59 } | |
60 | |
61 void[] init() | |
62 { static double r; | |
63 | |
64 return (cast(double *)&r)[0 .. 1]; | |
65 } | |
66 } | |
67 |