| 1 |
// https://issues.dlang.org/show_bug.cgi?id=21515 |
| 2 |
// DISABLED: win32 win64 |
| 3 |
|
| 4 |
// ABI layout of native complex |
| 5 |
struct _Complex(T) { T re; T im; } |
| 6 |
|
| 7 |
// Special enum definitions. |
| 8 |
version (Posix) |
| 9 |
{ |
| 10 |
align(float.alignof) enum __c_complex_float : _Complex!float; |
| 11 |
align(double.alignof) enum __c_complex_double : _Complex!double; |
| 12 |
align(real.alignof) enum __c_complex_real : _Complex!real; |
| 13 |
} |
| 14 |
else |
| 15 |
{ |
| 16 |
align(float.sizeof * 2) enum __c_complex_float : _Complex!float; |
| 17 |
align(double.sizeof * 2) enum __c_complex_double : _Complex!double; |
| 18 |
align(real.alignof) enum __c_complex_real : _Complex!real; |
| 19 |
} |
| 20 |
alias complex_float = __c_complex_float; |
| 21 |
alias complex_double = __c_complex_double; |
| 22 |
alias complex_real = __c_complex_real; |
| 23 |
|
| 24 |
extern(D) complex_float dcomplexf() { return typeof(return)(2, 1); } |
| 25 |
extern(D) complex_double dcomplex() { return typeof(return)(2, 1); } |
| 26 |
extern(D) complex_real dcomplexl() { return typeof(return)(2, 1); } |
| 27 |
|
| 28 |
extern(D) void dcomplexf(complex_float c) { assert(c.re == 2 && c.im == 1); } |
| 29 |
extern(D) void dcomplex(complex_double c) { assert(c.re == 2 && c.im == 1); } |
| 30 |
extern(D) void dcomplexl(complex_real c) { assert(c.re == 2 && c.im == 1); } |
| 31 |
|
| 32 |
extern(C) complex_float ccomplexf() { return typeof(return)(2, 1); } |
| 33 |
extern(C) complex_double ccomplex() { return typeof(return)(2, 1); } |
| 34 |
extern(C) complex_real ccomplexl() { return typeof(return)(2, 1); } |
| 35 |
|
| 36 |
extern(C) void ccomplexf2(complex_float c) { assert(c.re == 2 && c.im == 1); } |
| 37 |
extern(C) void ccomplex2(complex_double c) { assert(c.re == 2 && c.im == 1); } |
| 38 |
extern(C) void ccomplexl2(complex_real c) { assert(c.re == 2 && c.im == 1); } |
| 39 |
|
| 40 |
extern(C++) complex_float cpcomplexf() { return typeof(return)(2, 1); } |
| 41 |
extern(C++) complex_double cpcomplex() { return typeof(return)(2, 1); } |
| 42 |
extern(C++) complex_real cpcomplexl() { return typeof(return)(2, 1); } |
| 43 |
|
| 44 |
extern(C++) void cpcomplexf(complex_float c) { assert(c.re == 2 && c.im == 1); } |
| 45 |
extern(C++) void cpcomplex(complex_double c) { assert(c.re == 2 && c.im == 1); } |
| 46 |
extern(C++) void cpcomplexl(complex_real c) { assert(c.re == 2 && c.im == 1); } |
| 47 |
|
| 48 |
int main() |
| 49 |
{ |
| 50 |
auto a1 = dcomplexf(); |
| 51 |
auto b1 = dcomplex(); |
| 52 |
auto c1 = dcomplexl(); |
| 53 |
assert(a1.re == 2 && a1.im == 1); |
| 54 |
assert(b1.re == 2 && b1.im == 1); |
| 55 |
assert(c1.re == 2 && c1.im == 1); |
| 56 |
dcomplexf(a1); |
| 57 |
dcomplex(b1); |
| 58 |
dcomplexl(c1); |
| 59 |
|
| 60 |
auto a2 = ccomplexf(); |
| 61 |
auto b2 = ccomplex(); |
| 62 |
auto c2 = ccomplexl(); |
| 63 |
assert(a2.re == 2 && a2.im == 1); |
| 64 |
assert(b2.re == 2 && b2.im == 1); |
| 65 |
assert(c2.re == 2 && c2.im == 1); |
| 66 |
ccomplexf2(a2); |
| 67 |
ccomplex2(b2); |
| 68 |
ccomplexl2(c2); |
| 69 |
|
| 70 |
auto a3 = cpcomplexf(); |
| 71 |
auto b3 = cpcomplex(); |
| 72 |
auto c3 = cpcomplexl(); |
| 73 |
assert(a3.re == 2 && a3.im == 1); |
| 74 |
assert(b3.re == 2 && b3.im == 1); |
| 75 |
assert(c3.re == 2 && c3.im == 1); |
| 76 |
cpcomplexf(a3); |
| 77 |
cpcomplex(b3); |
| 78 |
cpcomplexl(c3); |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |