2010-03-09 18:51:30 -07:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// Copyright 2010 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
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
var a [12]complex128
|
|
|
|
var s []complex128
|
|
|
|
var c chan complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
var f struct {
|
2011-01-19 21:09:00 -07:00
|
|
|
c complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
}
|
2011-01-19 21:09:00 -07:00
|
|
|
var m map[complex128]complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
|
|
|
|
func main() {
|
2011-01-19 21:09:00 -07:00
|
|
|
// array of complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
for i := 0; i < len(a); i++ {
|
2011-01-19 21:09:00 -07:00
|
|
|
a[i] = complex(float64(i), float64(-i))
|
2010-03-09 18:51:30 -07:00
|
|
|
}
|
|
|
|
println(a[5])
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
// slice of complex128
|
|
|
|
s = make([]complex128, len(a))
|
2010-03-09 18:51:30 -07:00
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
s[i] = a[i]
|
|
|
|
}
|
|
|
|
println(s[5])
|
|
|
|
|
|
|
|
// chan
|
2011-01-19 21:09:00 -07:00
|
|
|
c = make(chan complex128)
|
2010-03-09 18:51:30 -07:00
|
|
|
go chantest(c)
|
|
|
|
println(<-c)
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
// pointer of complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
v := a[5]
|
|
|
|
pv := &v
|
|
|
|
println(*pv)
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
// field of complex128
|
2010-03-09 18:51:30 -07:00
|
|
|
f.c = a[5]
|
|
|
|
println(f.c)
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
// map of complex128
|
|
|
|
m = make(map[complex128]complex128)
|
2010-03-09 18:51:30 -07:00
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
m[-a[i]] = a[i]
|
|
|
|
}
|
|
|
|
println(m[5i-5])
|
2011-01-19 21:09:00 -07:00
|
|
|
println(m[complex(-5, 5)])
|
2010-03-09 18:51:30 -07:00
|
|
|
}
|
|
|
|
|
2011-01-19 21:09:00 -07:00
|
|
|
func chantest(c chan complex128) { c <- a[5] }
|