3 // Copyright 2009 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 simple boolean and numeric constants.
32 fhuge float64 = 1 << 100
33 fhuge_1 float64 = chuge - 1
34 f1 float64 = chuge >> 100
39 func assert(t bool, s string) {
48 assert(chuge > chuge_1, "chuge")
49 assert(chuge_1+1 == chuge, "chuge 1")
50 assert(chuge+cm1+1 == chuge, "cm1")
51 assert(c3div2 == 1, "3/2")
52 assert(c1e3 == 1000, "c1e3 int")
53 assert(c1e3 == 1e3, "c1e3 float")
54 assert(rsh1 == 0, "rsh1")
55 assert(rsh2 == 9, "rsh2")
57 // verify that all (in range) are assignable as ints
60 assert(i == c0, "i == c0")
62 assert(i == cm1, "i == cm1")
64 assert(i == c1, "i == c1")
66 assert(i == c3div2, "i == c3div2")
68 assert(i == c1e3, "i == c1e3")
70 // verify that all are assignable as floats
73 assert(f == c0, "f == c0")
75 assert(f == cm1, "f == cm1")
77 assert(f == chuge, "f == chuge")
79 assert(f == chuge_1, "f == chuge_1")
81 assert(f == c1, "f == c1")
83 assert(f == c3div2, "f == c3div2")
85 assert(f == c1e3, "f == c1e3")
89 assert(f0 == c0, "f0")
90 assert(f1 == c1, "f1")
91 // TODO(gri): exp/ssa/interp constant folding is incorrect.
92 if os.Getenv("GOSSAINTERP") == "" {
93 assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
95 assert(fhuge_1+1 == fhuge, "fhuge 1")
96 assert(fhuge+fm1+1 == fhuge, "fm1")
97 assert(f3div2 == 1.5, "3./2.")
98 assert(f1e3 == 1000, "f1e3 int")
99 assert(f1e3 == 1.e3, "f1e3 float")
101 // verify that all (in range) are assignable as ints
104 assert(i == f0, "i == f0")
106 assert(i == fm1, "i == fm1")
108 // verify that all are assignable as floats
111 assert(f == f0, "f == f0")
113 assert(f == fm1, "f == fm1")
115 assert(f == fhuge, "f == fhuge")
117 assert(f == fhuge_1, "f == fhuge_1")
119 assert(f == f1, "f == f1")
121 assert(f == f3div2, "f == f3div2")
123 assert(f == f1e3, "f == f1e3")
132 _ = nil == interface{}(nil)
133 _ = interface{}(nil) == nil
135 ii := func(i1 interface{}, i2 interface{}) bool { return i1 == i2 }
136 ni := func(n interface{}, i int) bool { return n == i }
137 in := func(i int, n interface{}) bool { return i == n }
138 pi := func(p *int, i interface{}) bool { return p == i }
139 ip := func(i interface{}, p *int) bool { return i == p }
141 assert((interface{}(nil) == interface{}(nil)) == ii(nilN, nilN),
142 "for interface{}==interface{} compiler == runtime")
144 assert(((*int)(nil) == interface{}(nil)) == pi(nilI, nilN),
145 "for *int==interface{} compiler == runtime")
146 assert((interface{}(nil) == (*int)(nil)) == ip(nilN, nilI),
147 "for interface{}==*int compiler == runtime")
149 assert((&five == interface{}(nil)) == pi(&five, nilN),
150 "for interface{}==*int compiler == runtime")
151 assert((interface{}(nil) == &five) == ip(nilN, &five),
152 "for interface{}==*int compiler == runtime")
154 assert((5 == interface{}(5)) == ni(five, five),
155 "for int==interface{} compiler == runtime")
156 assert((interface{}(5) == 5) == in(five, five),
157 "for interface{}==int comipiler == runtime")
165 assert(ctrue == true, "ctrue == true")
166 assert(cfalse == false, "cfalse == false")