Ken Thompson | f229c8b | 2010-03-09 12:49:24 -0800 | [diff] [blame^] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out |
Ken Thompson | 426099f | 2010-03-05 20:16:04 -0800 | [diff] [blame] | 2 | |
Ken Thompson | f229c8b | 2010-03-09 12:49:24 -0800 | [diff] [blame^] | 3 | // Copyright 2010 The Go Authors. All rights reserved. |
Ken Thompson | 426099f | 2010-03-05 20:16:04 -0800 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
| 7 | package main |
| 8 | |
| 9 | import "fmt" |
| 10 | |
| 11 | const ( |
| 12 | R = 5 |
| 13 | I = 6i |
| 14 | |
| 15 | C1 = R + I // ADD(5,6) |
| 16 | ) |
| 17 | |
| 18 | func doprint(c complex) { |
| 19 | fmt.Printf("c = %f\n", c) |
| 20 | } |
| 21 | |
| 22 | func main() { |
| 23 | |
| 24 | // constants |
| 25 | fmt.Printf("c = %f\n", -C1) |
| 26 | doprint(C1) |
| 27 | |
| 28 | // variables |
| 29 | c1 := C1 |
| 30 | fmt.Printf("c = %f\n", c1) |
| 31 | doprint(c1) |
| 32 | |
| 33 | // 128 |
| 34 | c2 := complex128(C1) |
| 35 | fmt.Printf("c = %G\n", c2) |
| 36 | |
| 37 | // real, imag, cmplx |
| 38 | c3 := cmplx(real(c2)+3, imag(c2)-5) + c2 |
| 39 | fmt.Printf("c = %G\n", c3) |
| 40 | } |