summaryrefslogtreecommitdiff
path: root/test/ken
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2010-03-02 18:32:11 -0800
committerKen Thompson <ken@golang.org>2010-03-02 18:32:11 -0800
commit3c9570d20599b41655a2b35712d35afa94fe5ac8 (patch)
tree73ab3f3de5c40ec909e5426aa34fdb707769a3be /test/ken
parentbd1d8f84d237e8a69cf30afdcc8e887eec37a2f4 (diff)
downloadgo-3c9570d20599b41655a2b35712d35afa94fe5ac8.tar.gz
more on type complex.
getting close. R=rsc CC=golang-dev http://codereview.appspot.com/224105
Diffstat (limited to 'test/ken')
-rw-r--r--test/ken/cplx0.go28
-rw-r--r--test/ken/cplx1.go85
-rw-r--r--test/ken/cplx2.go95
3 files changed, 208 insertions, 0 deletions
diff --git a/test/ken/cplx0.go b/test/ken/cplx0.go
new file mode 100644
index 000000000..cf78e5719
--- /dev/null
+++ b/test/ken/cplx0.go
@@ -0,0 +1,28 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+const (
+ R = 5
+ I = 6i
+
+ C1 = R + I // ADD(5,6)
+)
+
+func doprint(c complex) { println(c) }
+
+func main() {
+
+ // constants
+ println(C1)
+ doprint(C1)
+
+ // variables
+ c1 := C1
+ println(c1)
+ doprint(c1)
+}
diff --git a/test/ken/cplx1.go b/test/ken/cplx1.go
new file mode 100644
index 000000000..4686a4e52
--- /dev/null
+++ b/test/ken/cplx1.go
@@ -0,0 +1,85 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+const (
+ R = 5
+ I = 6i
+
+ C1 = R + I // ADD(5,6)
+)
+
+func main() {
+ var b bool
+
+ // constants
+ b = (5 + 6i) == C1
+ if !b {
+ panicln("const bool 1", b)
+ }
+
+ b = (5 + 6i) != C1
+ if b {
+ panicln("const bool 2", b)
+ }
+
+ b = C1 == (5 + 6i)
+ if !b {
+ panicln("const bool 3", b)
+ }
+
+ b = C1 != (5 + 6i)
+ if b {
+ panicln("const bool 4", b)
+ }
+
+ // vars passed through parameters
+ booltest(5+6i, true)
+ booltest(5+7i, false)
+ booltest(6+6i, false)
+ booltest(6+9i, false)
+}
+
+func booltest(a complex, r bool) {
+ var b bool
+
+ b = a == C1
+ if b != r {
+ panicln("param bool 1", a, b, r)
+ }
+
+ b = a != C1
+ if b == r {
+ panicln("param bool 2", a, b, r)
+ }
+
+ b = C1 == a
+ if b != r {
+ panicln("param bool 3", a, b, r)
+ }
+
+ b = C1 != a
+ if b == r {
+ panicln("param bool 4", a, b, r)
+ }
+
+ if r {
+ if a != C1 {
+ panicln("param bool 5", a, b, r)
+ }
+ if C1 != a {
+ panicln("param bool 6", a, b, r)
+ }
+ } else {
+ if a == C1 {
+ panicln("param bool 6", a, b, r)
+ }
+ if C1 == a {
+ panicln("param bool 7", a, b, r)
+ }
+ }
+}
diff --git a/test/ken/cplx2.go b/test/ken/cplx2.go
new file mode 100644
index 000000000..06fd3812f
--- /dev/null
+++ b/test/ken/cplx2.go
@@ -0,0 +1,95 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+const (
+ R = 5
+ I = 6i
+
+ C1 = R + I // ADD(5,6)
+ C2 = R - I // SUB(5,-6)
+ C3 = -(R + I) // ADD(5,6) NEG(-5,-6)
+ C4 = -(R - I) // SUB(5,-6) NEG(-5,6)
+
+ C5 = C1 + R // ADD(10,6)
+ C6 = C1 + I // ADD(5,12)
+
+ Ca = C5 + C6 // ADD(15,18)
+ Cb = C5 - C6 // SUB(5,-6)
+
+ Cc = C5 * C6 // MUL(-22,-150)
+ Cd = C5 / C6 // DIV(0.721893,-0.532544)
+ Ce = Cd * C6 // MUL(10,6) sb C5
+)
+
+func main() {
+
+ r := 5 + 0i
+ if r != R {
+ panicln("opcode 1", r, R)
+ }
+
+ i := 6i
+ if i != I {
+ panicln("opcode 2", i, I)
+ }
+
+ c1 := r + i
+ if c1 != C1 {
+ panicln("opcode x", c1, C1)
+ }
+
+ c2 := r - i
+ if c2 != C2 {
+ panicln("opcode x", c2, C2)
+ }
+
+ c3 := -(r + i)
+ if c3 != C3 {
+ panicln("opcode x", c3, C3)
+ }
+
+ c4 := -(r - i)
+ if c4 != C4 {
+ panicln("opcode x", c4, C4)
+ }
+
+ c5 := c1 + r
+ if c5 != C5 {
+ panicln("opcode x", c5, C5)
+ }
+
+ c6 := c1 + i
+ if c6 != C6 {
+ panicln("opcode x", c6, C6)
+ }
+
+ ca := c5 + c6
+ if ca != Ca {
+ panicln("opcode x", ca, Ca)
+ }
+
+ cb := c5 - c6
+ if cb != Cb {
+ panicln("opcode x", cb, Cb)
+ }
+
+ cc := c5 * c6
+ if cc != Cc {
+ panicln("opcode x", cc, Cc)
+ }
+
+ cd := c5 / c6
+ if cd != Cd {
+ panicln("opcode x", cd, Cd)
+ }
+
+ ce := cd * c6
+ if ce != Ce {
+ panicln("opcode x", ce, Ce)
+ }
+}