comparison druntime/src/compiler/dmd/typeinfo/ti_cfloat.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_cfloat;
14
15 // cfloat
16
17 class TypeInfo_q : TypeInfo
18 {
19 override string toString() { return "cfloat"; }
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(cfloat f1, cfloat f2)
27 {
28 return f1 == f2;
29 }
30
31 static int _compare(cfloat f1, cfloat f2)
32 { int result;
33
34 if (f1.re < f2.re)
35 result = -1;
36 else if (f1.re > f2.re)
37 result = 1;
38 else if (f1.im < f2.im)
39 result = -1;
40 else if (f1.im > f2.im)
41 result = 1;
42 else
43 result = 0;
44 return result;
45 }
46
47 override equals_t equals(in void* p1, in void* p2)
48 {
49 return _equals(*cast(cfloat *)p1, *cast(cfloat *)p2);
50 }
51
52 override int compare(in void* p1, in void* p2)
53 {
54 return _compare(*cast(cfloat *)p1, *cast(cfloat *)p2);
55 }
56
57 override size_t tsize()
58 {
59 return cfloat.sizeof;
60 }
61
62 override void swap(void *p1, void *p2)
63 {
64 cfloat t;
65
66 t = *cast(cfloat *)p1;
67 *cast(cfloat *)p1 = *cast(cfloat *)p2;
68 *cast(cfloat *)p2 = t;
69 }
70
71 override void[] init()
72 { static immutable cfloat r;
73
74 return (cast(cfloat *)&r)[0 .. 1];
75 }
76 }