]> Cypherpunks.ru repositories - gostls13.git/blob - test/const.go
bugs related to constat types
[gostls13.git] / test / const.go
1 // $G $F.go && $L $F.$A && ./$A.out
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 package main
8
9 const (
10         c0 = 0;
11         cm1 = -1;
12         chuge = 1 << 100;
13         chuge_1 = chuge - 1;
14         c1 = chuge >> 100;
15         c3div2 = 3/2;
16         c1e3 = 1e3;
17 )
18
19 const (
20         f0 = 0.0;
21         fm1 = -1.;
22         fhuge float64 = 1 << 100;
23         fhuge_1 float64 = chuge - 1;
24         f1 float64 = chuge >> 100;
25         f3div2 = 3./2.;
26         f1e3 float64 = 1e3;
27 )
28
29 func assert(t bool, s string) {
30         if !t {
31                 panic(s)
32         }
33 }
34
35 func ints() {
36         assert(c0 == 0, "c0");
37         assert(c1 == 1, "c1");
38         assert(chuge > chuge_1, "chuge");
39         assert(chuge_1 + 1 == chuge, "chuge 1");
40         assert(chuge + cm1 +1  == chuge, "cm1");
41         assert(c3div2 == 1, "3/2");
42         assert(c1e3 == 1000, "c1e3 int");
43         assert(c1e3 == 1e3, "c1e3 float");
44
45         // verify that all (in range) are assignable as ints
46         var i int;
47         i = c0;
48         assert(i == c0, "i == c0");
49         i = cm1;
50         assert(i == cm1, "i == cm1");
51         i = c1;
52         assert(i == c1, "i == c1");
53         i = c3div2;
54         assert(i == c3div2, "i == c3div2");
55         i = c1e3;
56         assert(i == c1e3, "i == c1e3");
57
58         // verify that all are assignable as floats
59         var f float64;
60         f = c0;
61         assert(f == c0, "f == c0");
62         f = cm1;
63         assert(f == cm1, "f == cm1");
64         f = chuge;
65         assert(f == chuge, "f == chuge");
66         f = chuge_1;
67         assert(f == chuge_1, "f == chuge_1");
68         f = c1;
69         assert(f == c1, "f == c1");
70         f = c3div2;
71         assert(f == c3div2, "f == c3div2");
72         f = c1e3;
73         assert(f == c1e3, "f == c1e3");
74 }
75
76 func floats() {
77         assert(f0 == c0, "f0");
78         assert(f1 == c1, "f1");
79         assert(fhuge > fhuge_1, "fhuge");
80         assert(fhuge_1 + 1 == fhuge, "fhuge 1");
81         assert(fhuge + fm1 +1  == fhuge, "fm1");
82         assert(f3div2 == 1.5, "3./2.");
83         assert(f1e3 == 1000, "f1e3 int");
84         assert(f1e3 == 1.e3, "f1e3 float");
85
86         // verify that all (in range) are assignable as ints
87         var i int;
88         i = f0;
89         assert(i == f0, "i == f0");
90         i = fm1;
91         assert(i == fm1, "i == fm1");
92
93         // verify that all are assignable as floats
94         var f float64;
95         f = f0;
96         assert(f == f0, "f == f0");
97         f = fm1;
98         assert(f == fm1, "f == fm1");
99         f = fhuge;
100         assert(f == fhuge, "f == fhuge");
101         f = fhuge_1;
102         assert(f == fhuge_1, "f == fhuge_1");
103         f = f1;
104         assert(f == f1, "f == f1");
105         f = f3div2;
106         assert(f == f3div2, "f == f3div2");
107         f = f1e3;
108         assert(f == f1e3, "f == f1e3");
109 }
110
111 func main() {
112         ints();
113         floats();
114 }