blob: 34577a21e129023bfff500778b09f96eec8ba7af [file] [log] [blame]
Ken Thompsonf229c8b2010-03-09 12:49:24 -08001// $G $D/$F.go && $L $F.$A && ./$A.out
Ken Thompson426099f2010-03-05 20:16:04 -08002
Ken Thompsonf229c8b2010-03-09 12:49:24 -08003// Copyright 2010 The Go Authors. All rights reserved.
Ken Thompson426099f2010-03-05 20:16:04 -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
9import "fmt"
10
11const (
12 R = 5
13 I = 6i
14
15 C1 = R + I // ADD(5,6)
16)
17
18func doprint(c complex) {
19 fmt.Printf("c = %f\n", c)
20}
21
22func 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}