rust/tests/ui/consts/const-binops.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

127 lines
2.3 KiB
Rust
Raw Normal View History

// run-pass
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => ({
let (a, b) = (&$a, &$b);
assert!((*a - *b).abs() < 1.0e-6,
"{} is not approximately equal to {}", *a, *b);
})
}
2013-05-19 15:03:52 -05:00
static A: isize = -4 + 3;
static A2: usize = 3 + 3;
static B: f64 = 3.0 + 2.7;
2013-05-19 15:03:52 -05:00
static C: isize = 3 - 4;
static D: usize = 3 - 3;
static E: f64 = 3.0 - 2.7;
2013-05-19 15:03:52 -05:00
static E2: isize = -3 * 3;
static F: usize = 3 * 3;
static G: f64 = 3.3 * 3.3;
2013-05-19 15:03:52 -05:00
static H: isize = 3 / -1;
static I: usize = 3 / 3;
static J: f64 = 3.3 / 3.3;
2013-05-19 15:03:52 -05:00
static N: bool = true && false;
2013-05-19 15:03:52 -05:00
static O: bool = true || false;
2013-05-19 15:03:52 -05:00
static P: isize = 3 & 1;
static Q: usize = 1 & 3;
static R: isize = 3 | 1;
static S: usize = 1 | 3;
static T: isize = 3 ^ 1;
static U: usize = 1 ^ 3;
static V: isize = 1 << 3;
2013-05-19 15:03:52 -05:00
// NOTE: better shr coverage
static W: isize = 1024 >> 4;
static X: usize = 1024 >> 4;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static Y: bool = 1 == 1;
static Z: bool = 1.0f64 == 1.0;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static AA: bool = 1 <= 2;
static AB: bool = -1 <= 2;
static AC: bool = 1.0f64 <= 2.0;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static AD: bool = 1 < 2;
static AE: bool = -1 < 2;
static AF: bool = 1.0f64 < 2.0;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static AG: bool = 1 != 2;
static AH: bool = -1 != 2;
static AI: bool = 1.0f64 != 2.0;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static AJ: bool = 2 >= 1;
static AK: bool = 2 >= -2;
static AL: bool = 1.0f64 >= -2.0;
2013-05-19 15:03:52 -05:00
2015-01-25 15:05:03 -06:00
static AM: bool = 2 > 1;
static AN: bool = 2 > -2;
static AO: bool = 1.0f64 > -2.0;
2013-05-19 15:03:52 -05:00
pub fn main() {
assert_eq!(A, -1);
assert_eq!(A2, 6);
assert_approx_eq!(B, 5.7);
2013-05-19 15:03:52 -05:00
assert_eq!(C, -1);
assert_eq!(D, 0);
assert_approx_eq!(E, 0.3);
2013-05-19 15:03:52 -05:00
assert_eq!(E2, -9);
assert_eq!(F, 9);
assert_approx_eq!(G, 10.89);
2013-05-19 15:03:52 -05:00
assert_eq!(H, -3);
assert_eq!(I, 1);
assert_approx_eq!(J, 1.0);
2013-05-19 15:03:52 -05:00
assert_eq!(N, false);
2013-05-19 15:03:52 -05:00
assert_eq!(O, true);
2013-05-19 15:03:52 -05:00
assert_eq!(P, 1);
assert_eq!(Q, 1);
2013-05-19 15:03:52 -05:00
assert_eq!(R, 3);
assert_eq!(S, 3);
2013-05-19 15:03:52 -05:00
assert_eq!(T, 2);
assert_eq!(U, 2);
2013-05-19 15:03:52 -05:00
assert_eq!(V, 8);
2013-05-19 15:03:52 -05:00
assert_eq!(W, 64);
assert_eq!(X, 64);
2013-05-19 15:03:52 -05:00
assert_eq!(Y, true);
assert_eq!(Z, true);
2013-05-19 15:03:52 -05:00
assert_eq!(AA, true);
assert_eq!(AB, true);
assert_eq!(AC, true);
2013-05-19 15:03:52 -05:00
assert_eq!(AD, true);
assert_eq!(AE, true);
assert_eq!(AF, true);
2013-05-19 15:03:52 -05:00
assert_eq!(AG, true);
assert_eq!(AH, true);
assert_eq!(AI, true);
2013-05-19 15:03:52 -05:00
assert_eq!(AJ, true);
assert_eq!(AK, true);
assert_eq!(AL, true);
2013-05-19 15:03:52 -05:00
assert_eq!(AM, true);
assert_eq!(AN, true);
assert_eq!(AO, true);
2013-05-19 15:03:52 -05:00
}