diff options
author | Ken Thompson <ken@golang.org> | 2010-03-05 20:16:04 -0800 |
---|---|---|
committer | Ken Thompson <ken@golang.org> | 2010-03-05 20:16:04 -0800 |
commit | 518f85d44efefe4203efb2c1cae7ca597ad1e1cc (patch) | |
tree | 762fd17775da62a5871b43cb2d8e2fc5061e01fa /test/ken | |
parent | 257a8357ca674f316dcbfef1dee4fa9c8e9fc2ae (diff) | |
download | go-518f85d44efefe4203efb2c1cae7ca597ad1e1cc.tar.gz |
6g complex type usable
8g and 5g have stubs to ignore complex
R=rsc
CC=golang-dev
http://codereview.appspot.com/257042
Diffstat (limited to 'test/ken')
-rw-r--r-- | test/ken/cplx0.go | 4 | ||||
-rw-r--r-- | test/ken/cplx3.go | 42 | ||||
-rw-r--r-- | test/ken/cplx4.go | 40 |
3 files changed, 83 insertions, 3 deletions
diff --git a/test/ken/cplx0.go b/test/ken/cplx0.go index b9de2292b..b9e783029 100644 --- a/test/ken/cplx0.go +++ b/test/ken/cplx0.go @@ -1,6 +1,4 @@ -// true # disabled until 8g has complex - -// $G $D/$F.go && $L $F.$A && ./$A.out +// true // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/ken/cplx3.go b/test/ken/cplx3.go new file mode 100644 index 000000000..f08e9def9 --- /dev/null +++ b/test/ken/cplx3.go @@ -0,0 +1,42 @@ +// true + +// 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 + +import "unsafe" +import "reflect" + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +var complexBits = reflect.Typeof(complex(0i)).Size() * 8 + +func main() { + c0 := C1 + c0 = (c0+c0+c0) / (c0+c0) + println(c0) + + c := *(*complex)(unsafe.Pointer(&c0)) + println(c) + + println(complexBits) + + var a interface{} + switch c := reflect.NewValue(a).(type) { + case *reflect.Complex64Value: + v := c.Get() + _,_ = complex64(v), true + case *reflect.ComplexValue: + if complexBits == 64 { + v := c.Get() + _,_ = complex64(v), true + } + } +} diff --git a/test/ken/cplx4.go b/test/ken/cplx4.go new file mode 100644 index 000000000..d29a1c80c --- /dev/null +++ b/test/ken/cplx4.go @@ -0,0 +1,40 @@ +// true + +// 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 + +import "fmt" + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func doprint(c complex) { + fmt.Printf("c = %f\n", c) +} + +func main() { + + // constants + fmt.Printf("c = %f\n", -C1) + doprint(C1) + + // variables + c1 := C1 + fmt.Printf("c = %f\n", c1) + doprint(c1) + + // 128 + c2 := complex128(C1) + fmt.Printf("c = %G\n", c2) + + // real, imag, cmplx + c3 := cmplx(real(c2)+3, imag(c2)-5) + c2 + fmt.Printf("c = %G\n", c3) +} |