summaryrefslogtreecommitdiff
path: root/test/ken/cplx4.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/ken/cplx4.go')
-rw-r--r--test/ken/cplx4.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/test/ken/cplx4.go b/test/ken/cplx4.go
index 8524e47ae..738afcd2c 100644
--- a/test/ken/cplx4.go
+++ b/test/ken/cplx4.go
@@ -15,30 +15,44 @@ const (
C1 = R + I // ADD(5,6)
)
-func doprint(c complex128) { fmt.Printf("c = %f\n", c) }
+func want(s, w string) {
+ if s != w {
+ panic(s + " != " + w)
+ }
+}
+
+func doprint(c complex128, w string) {
+ s := fmt.Sprintf("%f", c)
+ want(s, w)
+}
func main() {
// constants
- fmt.Printf("c = %f\n", -C1)
- doprint(C1)
+ s := fmt.Sprintf("%f", -C1)
+ want(s, "(-5.000000-6.000000i)")
+ doprint(C1, "(5.000000+6.000000i)")
// variables
c1 := C1
- fmt.Printf("c = %f\n", c1)
- doprint(c1)
+ s = fmt.Sprintf("%f", c1)
+ want(s, "(5.000000+6.000000i)")
+ doprint(c1, "(5.000000+6.000000i)")
// 128
c2 := complex128(C1)
- fmt.Printf("c = %G\n", c2)
+ s = fmt.Sprintf("%G", c2)
+ want(s, "(5+6i)")
// real, imag, complex
c3 := complex(real(c2)+3, imag(c2)-5) + c2
- fmt.Printf("c = %G\n", c3)
+ s = fmt.Sprintf("%G", c3)
+ want(s, "(13+7i)")
// compiler used to crash on nested divide
c4 := complex(real(c3/2), imag(c3/2))
if c4 != c3/2 {
fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4)
+ panic(0)
}
}