From 803156b0356dc28005a7a07e52587d2d7894a8e3 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 28 May 2009 20:26:26 +0200 Subject: [PATCH] Allow complex -> integral casts. --- gen/complex.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gen/complex.cpp b/gen/complex.cpp index 08c46f63..731e45d5 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -438,11 +438,19 @@ DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) DImValue* im = new DImValue(to, impart); return DtoCastFloat(loc, im, to); } - else if (to->isfloating()) { + else if (to->isfloating() || to->isintegral()) { // FIXME: this loads both values, even when we only need one LLValue* v = val->getRVal(); LLValue* repart = gIR->ir->CreateExtractValue(v, 0, ".re_part"); - DImValue* re = new DImValue(to, repart); + Type *extractty; + if (vty->ty == Tcomplex32) { + extractty = Type::tfloat32; + } else if (vty->ty == Tcomplex64) { + extractty = Type::tfloat64; + } else if (vty->ty == Tcomplex80) { + extractty = Type::tfloat80; + } + DImValue* re = new DImValue(extractty, repart); return DtoCastFloat(loc, re, to); } else if (to->ty == Tbool) {