OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [const.go] - Blame information for rev 700

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.