Mercurial > projects > ddmd
diff dmd/expression/Neg.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | e28b18c23469 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/expression/Neg.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,33 @@ +module dmd.expression.Neg; + +import dmd.Type; +import dmd.Loc; +import dmd.RealExp; +import dmd.Expression; +import dmd.ComplexExp; +import dmd.IntegerExp; +import dmd.Complex; + +Expression Neg(Type type, Expression e1) +{ + Expression e; + Loc loc = e1.loc; + + if (e1.type.isreal()) + { + e = new RealExp(loc, -e1.toReal(), type); + } + else if (e1.type.isimaginary()) + { + e = new RealExp(loc, -e1.toImaginary(), type); + } + else if (e1.type.iscomplex()) + { + Complex!(real) c = e1.toComplex(); + e = new ComplexExp(loc, Complex!(real)(-c.re, -c.im), type); + } + else + e = new IntegerExp(loc, -e1.toInteger(), type); + + return e; +} \ No newline at end of file