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