]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/const-binops.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.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 // pretty-expanded FIXME #23616
12
13 macro_rules! assert_approx_eq {
14     ($a:expr, $b:expr) => ({
15         use std::num::Float;
16         let (a, b) = (&$a, &$b);
17         assert!((*a - *b).abs() < 1.0e-6,
18                 "{} is not approximately equal to {}", *a, *b);
19     })
20 }
21
22 static A: int = -4 + 3;
23 static A2: uint = 3 + 3;
24 static B: f64 = 3.0 + 2.7;
25
26 static C: int = 3 - 4;
27 static D: uint = 3 - 3;
28 static E: f64 = 3.0 - 2.7;
29
30 static E2: int = -3 * 3;
31 static F: uint = 3 * 3;
32 static G: f64 = 3.3 * 3.3;
33
34 static H: int = 3 / -1;
35 static I: uint = 3 / 3;
36 static J: f64 = 3.3 / 3.3;
37
38 static N: bool = true && false;
39
40 static O: bool = true || false;
41
42 static P: int = 3 & 1;
43 static Q: uint = 1 & 3;
44
45 static R: int = 3 | 1;
46 static S: uint = 1 | 3;
47
48 static T: int = 3 ^ 1;
49 static U: uint = 1 ^ 3;
50
51 static V: int = 1 << 3;
52
53 // NOTE: better shr coverage
54 static W: int = 1024 >> 4;
55 static X: uint = 1024 >> 4;
56
57 static Y: bool = 1 == 1;
58 static Z: bool = 1.0f64 == 1.0;
59
60 static AA: bool = 1 <= 2;
61 static AB: bool = -1 <= 2;
62 static AC: bool = 1.0f64 <= 2.0;
63
64 static AD: bool = 1 < 2;
65 static AE: bool = -1 < 2;
66 static AF: bool = 1.0f64 < 2.0;
67
68 static AG: bool = 1 != 2;
69 static AH: bool = -1 != 2;
70 static AI: bool = 1.0f64 != 2.0;
71
72 static AJ: bool = 2 >= 1;
73 static AK: bool = 2 >= -2;
74 static AL: bool = 1.0f64 >= -2.0;
75
76 static AM: bool = 2 > 1;
77 static AN: bool = 2 > -2;
78 static AO: bool = 1.0f64 > -2.0;
79
80 pub fn main() {
81     assert_eq!(A, -1);
82     assert_eq!(A2, 6);
83     assert_approx_eq!(B, 5.7);
84
85     assert_eq!(C, -1);
86     assert_eq!(D, 0);
87     assert_approx_eq!(E, 0.3);
88
89     assert_eq!(E2, -9);
90     assert_eq!(F, 9);
91     assert_approx_eq!(G, 10.89);
92
93     assert_eq!(H, -3);
94     assert_eq!(I, 1);
95     assert_approx_eq!(J, 1.0);
96
97     assert_eq!(N, false);
98
99     assert_eq!(O, true);
100
101     assert_eq!(P, 1);
102     assert_eq!(Q, 1);
103
104     assert_eq!(R, 3);
105     assert_eq!(S, 3);
106
107     assert_eq!(T, 2);
108     assert_eq!(U, 2);
109
110     assert_eq!(V, 8);
111
112     assert_eq!(W, 64);
113     assert_eq!(X, 64);
114
115     assert_eq!(Y, true);
116     assert_eq!(Z, true);
117
118     assert_eq!(AA, true);
119     assert_eq!(AB, true);
120     assert_eq!(AC, true);
121
122     assert_eq!(AD, true);
123     assert_eq!(AE, true);
124     assert_eq!(AF, true);
125
126     assert_eq!(AG, true);
127     assert_eq!(AH, true);
128     assert_eq!(AI, true);
129
130     assert_eq!(AJ, true);
131     assert_eq!(AK, true);
132     assert_eq!(AL, true);
133
134     assert_eq!(AM, true);
135     assert_eq!(AN, true);
136     assert_eq!(AO, true);
137 }