Source file
test/ken/cplx2.go
1
2
3
4
5
6
7
8
9 package main
10
11 const (
12 R = 5
13 I = 6i
14
15 C1 = R + I
16 C2 = R - I
17 C3 = -(R + I)
18 C4 = -(R - I)
19
20 C5 = C1 + R
21 C6 = C1 + I
22
23 Ca = C5 + C6
24 Cb = C5 - C6
25
26 Cc = C5 * C6
27 Cd = C5 / C6
28 Ce = Cd * C6
29 )
30
31 func main() {
32
33 var r complex64 = 5 + 0i
34 if r != R {
35 println("opcode 1", r, R)
36 panic("fail")
37 }
38
39 var i complex64 = 6i
40 if i != I {
41 println("opcode 2", i, I)
42 panic("fail")
43 }
44
45 c1 := r + i
46 if c1 != C1 {
47 println("opcode x", c1, C1)
48 panic("fail")
49 }
50
51 c2 := r - i
52 if c2 != C2 {
53 println("opcode x", c2, C2)
54 panic("fail")
55 }
56
57 c3 := -(r + i)
58 if c3 != C3 {
59 println("opcode x", c3, C3)
60 panic("fail")
61 }
62
63 c4 := -(r - i)
64 if c4 != C4 {
65 println("opcode x", c4, C4)
66 panic("fail")
67 }
68
69 c5 := c1 + r
70 if c5 != C5 {
71 println("opcode x", c5, C5)
72 panic("fail")
73 }
74
75 c6 := c1 + i
76 if c6 != C6 {
77 println("opcode x", c6, C6)
78 panic("fail")
79 }
80
81 ca := c5 + c6
82 if ca != Ca {
83 println("opcode x", ca, Ca)
84 panic("fail")
85 }
86
87 cb := c5 - c6
88 if cb != Cb {
89 println("opcode x", cb, Cb)
90 panic("fail")
91 }
92
93 cc := c5 * c6
94 if cc != Cc {
95 println("opcode x", cc, Cc)
96 panic("fail")
97 }
98
99 cd := c5 / c6
100 if cd != Cd {
101 println("opcode x", cd, Cd)
102 panic("fail")
103 }
104
105 ce := cd * c6
106 if ce != Ce {
107 println("opcode x", ce, Ce)
108 panic("fail")
109 }
110
111 r32 := real(complex64(ce))
112 if r32 != float32(real(Ce)) {
113 println("real(complex64(ce))", r32, real(Ce))
114 panic("fail")
115 }
116
117 r64 := real(complex128(ce))
118 if r64 != real(Ce) {
119 println("real(complex128(ce))", r64, real(Ce))
120 panic("fail")
121 }
122 }
123
View as plain text