Mercurial > projects > dstress
comparison run/creal_15.d @ 1602:56d43974b468
Fix broken tests fvbommel pointed out in #2.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Mar 2009 15:48:16 +0100 |
parents | 5511f9277078 |
children |
comparison
equal
deleted
inserted
replaced
1601:90bc51a580b7 | 1602:56d43974b468 |
---|---|
2 // $Date$ | 2 // $Date$ |
3 // $Author$ | 3 // $Author$ |
4 | 4 |
5 module dstress.run.creal_15; | 5 module dstress.run.creal_15; |
6 | 6 |
7 bool isIdentical(real x, real y) | |
8 { | |
9 long* x64 = cast(long*)&x; | |
10 long* y64 = cast(long*)&y; | |
11 ushort* x16 = cast(ushort*)&x + 4; | |
12 ushort* y16 = cast(ushort*)&y + 4; | |
13 return *x64 == *y64 && *x16 == *y16; | |
14 } | |
15 | |
7 int main(){ | 16 int main(){ |
8 creal a = creal.nan; | 17 creal a = creal.nan; |
9 creal b; | 18 creal b; |
10 byte* X = cast(byte*)(cast(void*)&a); | |
11 | 19 |
12 b = real.nan + ireal.nan; | 20 b = real.nan + ireal.nan; |
13 byte* Y = cast(byte*)(cast(void*)&b); | 21 assert(isIdentical(a.re, b.re)); |
22 assert(isIdentical(a.im, b.im)); | |
14 | 23 |
15 for(size_t i=0; i<a.sizeof; i++){ | 24 real c = real.nan; |
16 assert(X[i]==Y[i]); | 25 |
17 } | |
18 | |
19 real c= real.nan; | |
20 real d=a.re; | 26 real d=a.re; |
21 X = cast(byte*)(cast(void*)&c); | 27 assert(isIdentical(c, d)); |
22 Y = cast(byte*)(cast(void*)&d); | |
23 | |
24 for(size_t i=0; i<c.sizeof; i++){ | |
25 assert(X[i]==Y[i]); | |
26 } | |
27 | 28 |
28 d=a.im; | 29 d=a.im; |
29 X = cast(byte*)(cast(void*)&c); | 30 assert(isIdentical(c, d)); |
30 Y = cast(byte*)(cast(void*)&d); | 31 |
31 for(size_t i=0; i<c.sizeof; i++){ | |
32 assert(X[i]==Y[i]); | |
33 } | |
34 | |
35 return 0; | 32 return 0; |
36 } | 33 } |