]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/const-binops.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / const-binops.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 macro_rules! assert_approx_eq {
13 ($a:expr, $b:expr) => ({
14 let (a, b) = (&$a, &$b);
15 assert!((*a - *b).abs() < 1.0e-6,
16 "{} is not approximately equal to {}", *a, *b);
17 })
18 }
19
20 static A: isize = -4 + 3;
21 static A2: usize = 3 + 3;
22 static B: f64 = 3.0 + 2.7;
23
24 static C: isize = 3 - 4;
25 static D: usize = 3 - 3;
26 static E: f64 = 3.0 - 2.7;
27
28 static E2: isize = -3 * 3;
29 static F: usize = 3 * 3;
30 static G: f64 = 3.3 * 3.3;
31
32 static H: isize = 3 / -1;
33 static I: usize = 3 / 3;
34 static J: f64 = 3.3 / 3.3;
35
36 static N: bool = true && false;
37
38 static O: bool = true || false;
39
40 static P: isize = 3 & 1;
41 static Q: usize = 1 & 3;
42
43 static R: isize = 3 | 1;
44 static S: usize = 1 | 3;
45
46 static T: isize = 3 ^ 1;
47 static U: usize = 1 ^ 3;
48
49 static V: isize = 1 << 3;
50
51 // NOTE: better shr coverage
52 static W: isize = 1024 >> 4;
53 static X: usize = 1024 >> 4;
54
55 static Y: bool = 1 == 1;
56 static Z: bool = 1.0f64 == 1.0;
57
58 static AA: bool = 1 <= 2;
59 static AB: bool = -1 <= 2;
60 static AC: bool = 1.0f64 <= 2.0;
61
62 static AD: bool = 1 < 2;
63 static AE: bool = -1 < 2;
64 static AF: bool = 1.0f64 < 2.0;
65
66 static AG: bool = 1 != 2;
67 static AH: bool = -1 != 2;
68 static AI: bool = 1.0f64 != 2.0;
69
70 static AJ: bool = 2 >= 1;
71 static AK: bool = 2 >= -2;
72 static AL: bool = 1.0f64 >= -2.0;
73
74 static AM: bool = 2 > 1;
75 static AN: bool = 2 > -2;
76 static AO: bool = 1.0f64 > -2.0;
77
78 pub fn main() {
79 assert_eq!(A, -1);
80 assert_eq!(A2, 6);
81 assert_approx_eq!(B, 5.7);
82
83 assert_eq!(C, -1);
84 assert_eq!(D, 0);
85 assert_approx_eq!(E, 0.3);
86
87 assert_eq!(E2, -9);
88 assert_eq!(F, 9);
89 assert_approx_eq!(G, 10.89);
90
91 assert_eq!(H, -3);
92 assert_eq!(I, 1);
93 assert_approx_eq!(J, 1.0);
94
95 assert_eq!(N, false);
96
97 assert_eq!(O, true);
98
99 assert_eq!(P, 1);
100 assert_eq!(Q, 1);
101
102 assert_eq!(R, 3);
103 assert_eq!(S, 3);
104
105 assert_eq!(T, 2);
106 assert_eq!(U, 2);
107
108 assert_eq!(V, 8);
109
110 assert_eq!(W, 64);
111 assert_eq!(X, 64);
112
113 assert_eq!(Y, true);
114 assert_eq!(Z, true);
115
116 assert_eq!(AA, true);
117 assert_eq!(AB, true);
118 assert_eq!(AC, true);
119
120 assert_eq!(AD, true);
121 assert_eq!(AE, true);
122 assert_eq!(AF, true);
123
124 assert_eq!(AG, true);
125 assert_eq!(AH, true);
126 assert_eq!(AI, true);
127
128 assert_eq!(AJ, true);
129 assert_eq!(AK, true);
130 assert_eq!(AL, true);
131
132 assert_eq!(AM, true);
133 assert_eq!(AN, true);
134 assert_eq!(AO, true);
135 }