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 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 18 | func doprint(c complex128) { fmt.Printf("c = %f\n", c) } |
Ken Thompson | 426099f | 2010-03-05 20:16:04 -0800 | [diff] [blame] | 19 | |
| 20 | func 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 Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 35 | // real, imag, complex |
| 36 | c3 := complex(real(c2)+3, imag(c2)-5) + c2 |
Ken Thompson | 426099f | 2010-03-05 20:16:04 -0800 | [diff] [blame] | 37 | fmt.Printf("c = %G\n", c3) |
Russ Cox | 6d8b810 | 2010-06-23 10:55:50 -0400 | [diff] [blame] | 38 | |
| 39 | // compiler used to crash on nested divide |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 40 | c4 := complex(real(c3/2), imag(c3/2)) |
Russ Cox | 6d8b810 | 2010-06-23 10:55:50 -0400 | [diff] [blame] | 41 | if c4 != c3/2 { |
Kai Backman | 36057e7 | 2010-07-20 15:53:16 +0300 | [diff] [blame] | 42 | fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4) |
Russ Cox | 6d8b810 | 2010-06-23 10:55:50 -0400 | [diff] [blame] | 43 | } |
Ken Thompson | 426099f | 2010-03-05 20:16:04 -0800 | [diff] [blame] | 44 | } |