Mercurial > projects > ldc
comparison druntime/src/compiler/dmd/typeinfo/ti_double.d @ 1458:e0b2d67cfe7c
Added druntime (this should be removed once it works).
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 02 Jun 2009 17:43:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1456:7b218ec1044f | 1458:e0b2d67cfe7c |
---|---|
1 /** | |
2 * TypeInfo support code. | |
3 * | |
4 * Copyright: Copyright Digital Mars 2004 - 2009. | |
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>. | |
6 * Authors: Walter Bright | |
7 * | |
8 * Copyright Digital Mars 2004 - 2009. | |
9 * Distributed under the Boost Software License, Version 1.0. | |
10 * (See accompanying file LICENSE_1_0.txt or copy at | |
11 * http://www.boost.org/LICENSE_1_0.txt) | |
12 */ | |
13 module rt.typeinfo.ti_double; | |
14 | |
15 // double | |
16 | |
17 class TypeInfo_d : TypeInfo | |
18 { | |
19 override string toString() { return "double"; } | |
20 | |
21 override hash_t getHash(in void* p) | |
22 { | |
23 return (cast(uint *)p)[0] + (cast(uint *)p)[1]; | |
24 } | |
25 | |
26 static equals_t _equals(double f1, double f2) | |
27 { | |
28 return f1 == f2 || | |
29 (f1 !<>= f1 && f2 !<>= f2); | |
30 } | |
31 | |
32 static int _compare(double d1, double d2) | |
33 { | |
34 if (d1 !<>= d2) // if either are NaN | |
35 { | |
36 if (d1 !<>= d1) | |
37 { if (d2 !<>= d2) | |
38 return 0; | |
39 return -1; | |
40 } | |
41 return 1; | |
42 } | |
43 return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); | |
44 } | |
45 | |
46 override equals_t equals(in void* p1, in void* p2) | |
47 { | |
48 return _equals(*cast(double *)p1, *cast(double *)p2); | |
49 } | |
50 | |
51 override int compare(in void* p1, in void* p2) | |
52 { | |
53 return _compare(*cast(double *)p1, *cast(double *)p2); | |
54 } | |
55 | |
56 override size_t tsize() | |
57 { | |
58 return double.sizeof; | |
59 } | |
60 | |
61 override void swap(void *p1, void *p2) | |
62 { | |
63 double t; | |
64 | |
65 t = *cast(double *)p1; | |
66 *cast(double *)p1 = *cast(double *)p2; | |
67 *cast(double *)p2 = t; | |
68 } | |
69 | |
70 override void[] init() | |
71 { static immutable double r; | |
72 | |
73 return (cast(double *)&r)[0 .. 1]; | |
74 } | |
75 } |