blob: 8524e47aec3b303a95b5e0fae2b3e9b32c1ac8df [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
Russ Coxf2b5a072011-01-19 23:09:00 -050018func doprint(c complex128) { fmt.Printf("c = %f\n", c) }
Ken Thompson426099f2010-03-05 20:16:04 -080019
20func main() {
21
22 // constants
23 fmt.Printf("c = %f\n", -C1)
24 doprint(C1)
25
26 // variables
27 c1 := C1
28 fmt.Printf("c = %f\n", c1)
29 doprint(c1)
30
31 // 128
32 c2 := complex128(C1)
33 fmt.Printf("c = %G\n", c2)
34
Russ Coxf2b5a072011-01-19 23:09:00 -050035 // real, imag, complex
36 c3 := complex(real(c2)+3, imag(c2)-5) + c2
Ken Thompson426099f2010-03-05 20:16:04 -080037 fmt.Printf("c = %G\n", c3)
Russ Cox6d8b8102010-06-23 10:55:50 -040038
39 // compiler used to crash on nested divide
Russ Coxf2b5a072011-01-19 23:09:00 -050040 c4 := complex(real(c3/2), imag(c3/2))
Russ Cox6d8b8102010-06-23 10:55:50 -040041 if c4 != c3/2 {
Kai Backman36057e72010-07-20 15:53:16 +030042 fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4)
Russ Cox6d8b8102010-06-23 10:55:50 -040043 }
Ken Thompson426099f2010-03-05 20:16:04 -080044}