Mercurial > projects > ldc
comparison lphobos/std/typeinfounsupported/ti_float.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 // float | |
3 | |
4 module std.typeinfo.ti_float; | |
5 | |
6 private import std.math; | |
7 | |
8 class TypeInfo_f : TypeInfo | |
9 { | |
10 char[] toString() { return "float"; } | |
11 | |
12 hash_t getHash(void *p) | |
13 { | |
14 return *cast(uint *)p; | |
15 } | |
16 | |
17 static int _equals(float f1, float f2) | |
18 { | |
19 return f1 == f2 || | |
20 (isnan(f1) && isnan(f2)); | |
21 } | |
22 | |
23 static int _compare(float d1, float 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(float *)p1, *cast(float *)p2); | |
40 } | |
41 | |
42 int compare(void *p1, void *p2) | |
43 { | |
44 return _compare(*cast(float *)p1, *cast(float *)p2); | |
45 } | |
46 | |
47 size_t tsize() | |
48 { | |
49 return float.sizeof; | |
50 } | |
51 | |
52 void swap(void *p1, void *p2) | |
53 { | |
54 float t; | |
55 | |
56 t = *cast(float *)p1; | |
57 *cast(float *)p1 = *cast(float *)p2; | |
58 *cast(float *)p2 = t; | |
59 } | |
60 | |
61 void[] init() | |
62 { static float r; | |
63 | |
64 return (cast(float *)&r)[0 .. 1]; | |
65 } | |
66 } | |
67 |