diff --git a/gen/complex.cpp b/gen/complex.cpp index a02e3598..a0c66c34 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -282,6 +282,24 @@ DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// +DValue* DtoComplexNeg(Type* type, DValue* val) +{ + val = DtoComplex(type, val); + + llvm::Value *a, *b, *re, *im; + + // values + DtoGetComplexParts(val, a, b); + + // sub up + re = gIR->ir->CreateNeg(a, "tmp"); + im = gIR->ir->CreateNeg(b, "tmp"); + + return new DComplexValue(type, re, im); +} + +////////////////////////////////////////////////////////////////////////////////////////// + llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) { Type* type = lhs->getType(); diff --git a/gen/complex.h b/gen/complex.h index 3ba79014..595fff71 100644 --- a/gen/complex.h +++ b/gen/complex.h @@ -23,6 +23,7 @@ DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs); DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs); DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs); DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs); +DValue* DtoComplexNeg(Type* type, DValue* val); llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs); diff --git a/gen/toir.cpp b/gen/toir.cpp index 8a28c48b..017d98db 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2394,8 +2394,12 @@ DValue* NegExp::toElem(IRState* p) LOG_SCOPE; DValue* l = e1->toElem(p); - llvm::Value* val = l->getRVal(); + if (type->iscomplex()) { + return DtoComplexNeg(type, l); + } + + llvm::Value* val = l->getRVal(); Type* t = DtoDType(type); llvm::Value* zero = 0; @@ -2407,7 +2411,10 @@ DValue* NegExp::toElem(IRState* p) else if (t->ty == Tfloat64 || t->ty == Tfloat80 || t->ty == Timaginary64 || t->ty == Timaginary80) zero = llvm::ConstantFP::get(val->getType(), llvm::APFloat(0.0)); else - assert(0); + { + Logger::println("unhandled fp negation of type %s", t->toChars()); + assert(0); + } } else assert(0); diff --git a/tango/tango/math/Math.d b/tango/tango/math/Math.d index ffa1119c..f99bdb15 100644 --- a/tango/tango/math/Math.d +++ b/tango/tango/math/Math.d @@ -369,6 +369,8 @@ real tan(real x) { version (GNU) { return tanl(x); + } else version (LLVMDC) { + return tango.stdc.math.tanl(x); } else { asm { diff --git a/tangotests/stdout2.d b/tangotests/stdout2.d index 12658f55..8c32e578 100644 --- a/tangotests/stdout2.d +++ b/tangotests/stdout2.d @@ -4,5 +4,5 @@ import tango.io.Stdout; void main() { - Stdout.formatln("{} {} {}", "a", "b", 1); + Stdout.formatln("{} {} {}", "a", "b", 1.0); }