blob: 7d3e5d735aff0530bcb0013245c6a8f4ed8b7aff [file] [log] [blame]
Ken Thompsonf229c8b2010-03-09 12:49:24 -08001// $G $D/$F.go && $L $F.$A && ./$A.out
Ken Thompson7d4b1e42010-03-02 18:32:11 -08002
Ken Thompsonf229c8b2010-03-09 12:49:24 -08003// Copyright 2010 The Go Authors. All rights reserved.
Ken Thompson7d4b1e42010-03-02 18:32:11 -08004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9const (
10 R = 5
11 I = 6i
12
13 C1 = R + I // ADD(5,6)
14 C2 = R - I // SUB(5,-6)
15 C3 = -(R + I) // ADD(5,6) NEG(-5,-6)
16 C4 = -(R - I) // SUB(5,-6) NEG(-5,6)
17
18 C5 = C1 + R // ADD(10,6)
19 C6 = C1 + I // ADD(5,12)
20
21 Ca = C5 + C6 // ADD(15,18)
22 Cb = C5 - C6 // SUB(5,-6)
23
24 Cc = C5 * C6 // MUL(-22,-150)
25 Cd = C5 / C6 // DIV(0.721893,-0.532544)
26 Ce = Cd * C6 // MUL(10,6) sb C5
27)
28
29func main() {
30
31 r := 5 + 0i
32 if r != R {
33 panicln("opcode 1", r, R)
34 }
35
36 i := 6i
37 if i != I {
38 panicln("opcode 2", i, I)
39 }
40
41 c1 := r + i
42 if c1 != C1 {
43 panicln("opcode x", c1, C1)
44 }
45
46 c2 := r - i
47 if c2 != C2 {
48 panicln("opcode x", c2, C2)
49 }
50
51 c3 := -(r + i)
52 if c3 != C3 {
53 panicln("opcode x", c3, C3)
54 }
55
56 c4 := -(r - i)
57 if c4 != C4 {
58 panicln("opcode x", c4, C4)
59 }
60
61 c5 := c1 + r
62 if c5 != C5 {
63 panicln("opcode x", c5, C5)
64 }
65
66 c6 := c1 + i
67 if c6 != C6 {
68 panicln("opcode x", c6, C6)
69 }
70
71 ca := c5 + c6
72 if ca != Ca {
73 panicln("opcode x", ca, Ca)
74 }
75
76 cb := c5 - c6
77 if cb != Cb {
78 panicln("opcode x", cb, Cb)
79 }
80
81 cc := c5 * c6
82 if cc != Cc {
83 panicln("opcode x", cc, Cc)
84 }
85
86 cd := c5 / c6
87 if cd != Cd {
88 panicln("opcode x", cd, Cd)
89 }
90
91 ce := cd * c6
92 if ce != Ce {
93 panicln("opcode x", ce, Ce)
94 }
95}