]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/const-int-overflowing.rs
const-int-overflowing.rs += overflowing_neg
[rust.git] / src / test / run-pass / const-int-overflowing.rs
1 const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
2 const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
3
4 const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
5 const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
6
7 const MUL_A: (u32, bool) = 5u32.overflowing_mul(2);
8 const MUL_B: (u32, bool) = 1_000_000_000u32.overflowing_mul(10);
9
10 const SHL_A: (u32, bool) = 0x1u32.overflowing_shl(4);
11 const SHL_B: (u32, bool) = 0x1u32.overflowing_shl(132);
12
13 const SHR_A: (u32, bool) = 0x10u32.overflowing_shr(4);
14 const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
15
16 const NEG_A: (u32, bool) = 0.overflowing_neg();
17 const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
18
19 fn ident<T>(ident: T) -> T {
20     ident
21 }
22
23 fn main() {
24     assert_eq!(ADD_A, ident((7, false)));
25     assert_eq!(ADD_B, ident((0, true)));
26
27     assert_eq!(SUB_A, ident((3, false)));
28     assert_eq!(SUB_B, ident((u32::max_value(), true)));
29
30     assert_eq!(MUL_A, ident((10, false)));
31     assert_eq!(MUL_B, ident((1410065408, true)));
32
33     assert_eq!(SHL_A, ident((0x10, false)));
34     assert_eq!(SHL_B, ident((0x10, true)));
35
36     assert_eq!(SHR_A, ident((0x1, false)));
37     assert_eq!(SHR_B, ident((0x1, true)));
38
39     assert_eq!(NEG_A, ident((0, false)));
40     assert_eq!(NEG_B, ident((1, true)));
41 }