3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test complex numbers,including fmt support.
18 C1 = R + I // ADD(5,6)
21 func want(s, w string) {
27 func doprint(c complex128, w string) {
28 s := fmt.Sprintf("%f", c)
35 s := fmt.Sprintf("%f", -C1)
36 want(s, "(-5.000000-6.000000i)")
37 doprint(C1, "(5.000000+6.000000i)")
41 s = fmt.Sprintf("%f", c1)
42 want(s, "(5.000000+6.000000i)")
43 doprint(c1, "(5.000000+6.000000i)")
47 s = fmt.Sprintf("%G", c2)
50 // real, imag, complex
51 c3 := complex(real(c2)+3, imag(c2)-5) + c2
52 s = fmt.Sprintf("%G", c3)
55 // compiler used to crash on nested divide
56 c4 := complex(real(c3/2), imag(c3/2))
58 fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4)