PageRenderTime 24ms CodeModel.GetById 1ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/runtime/typeinfo/ti_cfloat.d

http://github.com/wilkie/djehuty
D | 70 lines | 50 code | 14 blank | 6 comment | 9 complexity | 0bf853ac45ff85369274f0bbce20452d MD5 | raw file
 1/*
 2 * ti_cfloat.d
 3 *
 4 * This module implements the TypeInfo for the cfloat type.
 5 *
 6 */
 7
 8module runtime.typeinfo.ti_cfloat;
 9
10class TypeInfo_q : TypeInfo {
11	char[] toString() {
12		return "cfloat";
13	}
14
15	hash_t getHash(void *p) {
16		return (cast(uint *)p)[0] + (cast(uint *)p)[1];
17	}
18
19	static int _equals(cfloat f1, cfloat f2) {
20		return f1 == f2;
21	}
22
23	static int _compare(cfloat f1, cfloat f2) {
24		int result;
25
26		if (f1.re < f2.re) {
27			result = -1;
28		}
29		else if (f1.re > f2.re) {
30			result = 1;
31		}
32		else if (f1.im < f2.im) {
33			result = -1;
34		}
35		else if (f1.im > f2.im) {
36			result = 1;
37		}
38		else {
39			result = 0;
40		}
41
42		return result;
43	}
44
45	int equals(void *p1, void *p2) {
46		return _equals(*cast(cfloat *)p1, *cast(cfloat *)p2);
47	}
48
49	int compare(void *p1, void *p2) {
50		return _compare(*cast(cfloat *)p1, *cast(cfloat *)p2);
51	}
52
53	size_t tsize() {
54		return cfloat.sizeof;
55	}
56
57	void swap(void *p1, void *p2) {
58		cfloat t;
59
60		t = *cast(cfloat *)p1;
61		*cast(cfloat *)p1 = *cast(cfloat *)p2;
62		*cast(cfloat *)p2 = t;
63	}
64
65	void[] init() {
66		static cfloat r;
67
68		return (cast(cfloat *)&r)[0 .. 1];
69	}
70}