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.
36 fhuge
float64 = 1 << 100
37 fhuge_1
float64 = chuge
- 1
38 f1
float64 = chuge
>> 100
43 func assert(t
bool, s
string) {
52 assert(chuge
> chuge_1
, "chuge")
53 assert(chuge_1
+1 == chuge
, "chuge 1")
54 assert(chuge
+cm1
+1 == chuge
, "cm1")
55 assert(c3div2
== 1, "3/2")
56 assert(c1e3
== 1000, "c1e3 int")
57 assert(c1e3
== 1e3
, "c1e3 float")
58 assert(rsh1
== 0, "rsh1")
59 assert(rsh2
== 9, "rsh2")
61 // verify that all (in range) are assignable as ints
64 assert(i
== c0
, "i == c0")
66 assert(i
== cm1
, "i == cm1")
68 assert(i
== c1
, "i == c1")
70 assert(i
== c3div2
, "i == c3div2")
72 assert(i
== c1e3
, "i == c1e3")
74 // verify that all are assignable as floats
77 assert(f
== c0
, "f == c0")
79 assert(f
== cm1
, "f == cm1")
81 assert(f
== chuge
, "f == chuge")
83 assert(f
== chuge_1
, "f == chuge_1")
85 assert(f
== c1
, "f == c1")
87 assert(f
== c3div2
, "f == c3div2")
89 assert(f
== c1e3
, "f == c1e3")
93 assert(f0
== c0
, "f0")
94 assert(f1
== c1
, "f1")
95 // TODO(gri): exp/ssa/interp constant folding is incorrect.
96 if os
.Getenv("GOSSAINTERP") == "" {
97 assert(fhuge
== fhuge_1
, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
99 assert(fhuge_1
+1 == fhuge
, "fhuge 1")
100 assert(fhuge
+fm1
+1 == fhuge
, "fm1")
101 assert(f3div2
== 1.5, "3./2.")
102 assert(f1e3
== 1000, "f1e3 int")
103 assert(f1e3
== 1.e3
, "f1e3 float")
105 // verify that all (in range) are assignable as ints
108 assert(i
== f0
, "i == f0")
110 assert(i
== fm1
, "i == fm1")
112 // verify that all are assignable as floats
115 assert(f
== f0
, "f == f0")
117 assert(f
== fm1
, "f == fm1")
119 assert(f
== fhuge
, "f == fhuge")
121 assert(f
== fhuge_1
, "f == fhuge_1")
123 assert(f
== f1
, "f == f1")
125 assert(f
== f3div2
, "f == f3div2")
127 assert(f
== f1e3
, "f == f1e3")
136 _
= nil == interface{}(nil)
137 _
= interface{}(nil) == nil
139 ii
:= func(i1
interface{}, i2
interface{}) bool { return i1
== i2
}
140 ni
:= func(n
interface{}, i
int) bool { return n
== i
}
141 in
:= func(i
int, n
interface{}) bool { return i
== n
}
142 pi
:= func(p
*int, i
interface{}) bool { return p
== i
}
143 ip
:= func(i
interface{}, p
*int) bool { return i
== p
}
145 assert((interface{}(nil) == interface{}(nil)) == ii(nilN
, nilN
),
146 "for interface{}==interface{} compiler == runtime")
148 assert(((*int)(nil) == interface{}(nil)) == pi(nilI
, nilN
),
149 "for *int==interface{} compiler == runtime")
150 assert((interface{}(nil) == (*int)(nil)) == ip(nilN
, nilI
),
151 "for interface{}==*int compiler == runtime")
153 assert((&five
== interface{}(nil)) == pi(&five
, nilN
),
154 "for interface{}==*int compiler == runtime")
155 assert((interface{}(nil) == &five
) == ip(nilN
, &five
),
156 "for interface{}==*int compiler == runtime")
158 assert((5 == interface{}(5)) == ni(five
, five
),
159 "for int==interface{} compiler == runtime")
160 assert((interface{}(5) == 5) == in(five
, five
),
161 "for interface{}==int comipiler == runtime")
164 // Test that typed floating-point and complex arithmetic
165 // is computed with correct precision.
171 staticF32
= float32(x30
) + 1 - x30
172 staticF64
= float64(x60
) + 1 - x60
173 staticC64
= complex64(x30
) + 1 - x30
174 staticC128
= complex128(x60
) + 1 - x60
176 dynamicF32
:= float32(x30
)
180 dynamicF64
:= float64(x60
)
184 dynamicC64
:= complex64(x30
)
188 dynamicC128
:= complex128(x60
)
192 assert(staticF32
== 0, "staticF32 == 0")
193 assert(staticF64
== 0, "staticF64 == 0")
194 assert(dynamicF32
== 0, "dynamicF32 == 0")
195 assert(dynamicF64
== 0, "dynamicF64 == 0")
196 assert(staticC64
== 0, "staticC64 == 0")
197 assert(staticC128
== 0, "staticC128 == 0")
198 assert(dynamicC64
== 0, "dynamicC64 == 0")
199 assert(dynamicC128
== 0, "dynamicC128 == 0")
208 assert(ctrue
== true, "ctrue == true")
209 assert(cfalse
== false, "cfalse == false")