1// run
2
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.
6
7// Test simple boolean and numeric constants.
8
9package main
10
11const (
12	c0 = 0
13	cm1 = -1
14	chuge = 1 << 100
15	chuge_1 = chuge - 1
16	c1 = chuge >> 100
17	c3div2 = 3/2
18	c1e3 = 1e3
19
20	ctrue = true
21	cfalse = !ctrue
22)
23
24const (
25	f0 = 0.0
26	fm1 = -1.
27	fhuge float64 = 1 << 100
28	fhuge_1 float64 = chuge - 1
29	f1 float64 = chuge >> 100
30	f3div2 = 3./2.
31	f1e3 float64 = 1e3
32)
33
34func assert(t bool, s string) {
35	if !t {
36		panic(s)
37	}
38}
39
40func ints() {
41	assert(c0 == 0, "c0")
42	assert(c1 == 1, "c1")
43	assert(chuge > chuge_1, "chuge")
44	assert(chuge_1 + 1 == chuge, "chuge 1")
45	assert(chuge + cm1 +1  == chuge, "cm1")
46	assert(c3div2 == 1, "3/2")
47	assert(c1e3 == 1000, "c1e3 int")
48	assert(c1e3 == 1e3, "c1e3 float")
49
50	// verify that all (in range) are assignable as ints
51	var i int
52	i = c0
53	assert(i == c0, "i == c0")
54	i = cm1
55	assert(i == cm1, "i == cm1")
56	i = c1
57	assert(i == c1, "i == c1")
58	i = c3div2
59	assert(i == c3div2, "i == c3div2")
60	i = c1e3
61	assert(i == c1e3, "i == c1e3")
62
63	// verify that all are assignable as floats
64	var f float64
65	f = c0
66	assert(f == c0, "f == c0")
67	f = cm1
68	assert(f == cm1, "f == cm1")
69	f = chuge
70	assert(f == chuge, "f == chuge")
71	f = chuge_1
72	assert(f == chuge_1, "f == chuge_1")
73	f = c1
74	assert(f == c1, "f == c1")
75	f = c3div2
76	assert(f == c3div2, "f == c3div2")
77	f = c1e3
78	assert(f == c1e3, "f == c1e3")
79}
80
81func floats() {
82	assert(f0 == c0, "f0")
83	assert(f1 == c1, "f1")
84	assert(fhuge == fhuge_1, "fhuge")	// float64 can't distinguish fhuge, fhuge_1.
85	assert(fhuge_1 + 1 == fhuge, "fhuge 1")
86	assert(fhuge + fm1 +1  == fhuge, "fm1")
87	assert(f3div2 == 1.5, "3./2.")
88	assert(f1e3 == 1000, "f1e3 int")
89	assert(f1e3 == 1.e3, "f1e3 float")
90
91	// verify that all (in range) are assignable as ints
92	var i int
93	i = f0
94	assert(i == f0, "i == f0")
95	i = fm1
96	assert(i == fm1, "i == fm1")
97
98	// verify that all are assignable as floats
99	var f float64
100	f = f0
101	assert(f == f0, "f == f0")
102	f = fm1
103	assert(f == fm1, "f == fm1")
104	f = fhuge
105	assert(f == fhuge, "f == fhuge")
106	f = fhuge_1
107	assert(f == fhuge_1, "f == fhuge_1")
108	f = f1
109	assert(f == f1, "f == f1")
110	f = f3div2
111	assert(f == f3div2, "f == f3div2")
112	f = f1e3
113	assert(f == f1e3, "f == f1e3")
114}
115
116func main() {
117	ints()
118	floats()
119
120	assert(ctrue == true, "ctrue == true")
121	assert(cfalse == false, "cfalse == false")
122}
123