modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/ken/cplx1.go (about) 1 // run 2 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. 6 7 // Test simple arithmetic and assignment for complex numbers. 8 9 package main 10 11 const ( 12 R = 5 13 I = 6i 14 15 C1 = R + I // ADD(5,6) 16 ) 17 18 func main() { 19 var b bool 20 21 // constants 22 b = (5 + 6i) == C1 23 if !b { 24 println("const bool 1", b) 25 panic("fail") 26 } 27 28 b = (5 + 6i) != C1 29 if b { 30 println("const bool 2", b) 31 panic("fail") 32 } 33 34 b = C1 == (5 + 6i) 35 if !b { 36 println("const bool 3", b) 37 panic("fail") 38 } 39 40 b = C1 != (5 + 6i) 41 if b { 42 println("const bool 4", b) 43 panic("fail") 44 } 45 46 // vars passed through parameters 47 booltest(5+6i, true) 48 booltest(5+7i, false) 49 booltest(6+6i, false) 50 booltest(6+9i, false) 51 } 52 53 func booltest(a complex64, r bool) { 54 var b bool 55 56 b = a == C1 57 if b != r { 58 println("param bool 1", a, b, r) 59 panic("fail") 60 } 61 62 b = a != C1 63 if b == r { 64 println("param bool 2", a, b, r) 65 panic("fail") 66 } 67 68 b = C1 == a 69 if b != r { 70 println("param bool 3", a, b, r) 71 panic("fail") 72 } 73 74 b = C1 != a 75 if b == r { 76 println("param bool 4", a, b, r) 77 panic("fail") 78 } 79 80 if r { 81 if a != C1 { 82 println("param bool 5", a, b, r) 83 panic("fail") 84 } 85 if C1 != a { 86 println("param bool 6", a, b, r) 87 panic("fail") 88 } 89 } else { 90 if a == C1 { 91 println("param bool 6", a, b, r) 92 panic("fail") 93 } 94 if C1 == a { 95 println("param bool 7", a, b, r) 96 panic("fail") 97 } 98 } 99 }