0
|
1 module dmd.expression.Mul;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Type;
|
|
5 import dmd.Expression;
|
|
6 import dmd.RealExp;
|
|
7 import dmd.IntegerExp;
|
|
8 import dmd.ComplexExp;
|
|
9 import dmd.Loc;
|
|
10 import dmd.Complex;
|
|
11
|
|
12 Expression Mul(Type type, Expression e1, Expression e2)
|
|
13 {
|
|
14 Expression e;
|
|
15 Loc loc = e1.loc;
|
|
16
|
|
17 if (type.isfloating())
|
|
18 {
|
|
19 Complex!(real) c;
|
|
20 real r;
|
|
21
|
|
22 if (e1.type.isreal())
|
|
23 {
|
|
24 r = e1.toReal();
|
|
25 c = e2.toComplex();
|
|
26 c = Complex!(real)(r * c.re, r * c.im);
|
|
27 }
|
|
28 else if (e1.type.isimaginary())
|
|
29 {
|
|
30 r = e1.toImaginary();
|
|
31 c = e2.toComplex();
|
|
32 c = Complex!(real)(-r * c.im, r * c.re);
|
|
33 }
|
|
34 else if (e2.type.isreal())
|
|
35 {
|
114
|
36 r = e2.toReal();
|
0
|
37 c = e1.toComplex();
|
|
38 c = Complex!(real)(r * c.re, r * c.im);
|
|
39 }
|
|
40 else if (e2.type.isimaginary())
|
|
41 {
|
|
42 r = e2.toImaginary();
|
|
43 c = e1.toComplex();
|
|
44 c = Complex!(real)(-r * c.im, r * c.re);
|
|
45 }
|
|
46 else
|
|
47 {
|
|
48 Complex!(real) c1 = e1.toComplex();
|
|
49 Complex!(real) c2 = e2.toComplex();
|
|
50 c = Complex!(real)(c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
|
|
51 }
|
|
52
|
|
53 if (type.isreal())
|
|
54 e = new RealExp(loc, c.re, type);
|
|
55 else if (type.isimaginary())
|
|
56 e = new RealExp(loc, c.im, type);
|
|
57 else if (type.iscomplex())
|
|
58 e = new ComplexExp(loc, c, type);
|
|
59 else
|
|
60 assert(0);
|
|
61 }
|
|
62 else
|
|
63 {
|
|
64 e = new IntegerExp(loc, e1.toInteger() * e2.toInteger(), type);
|
|
65 }
|
|
66 return e;
|
|
67 } |