1 #![feature(const_int_overflowing)]
3 const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
4 const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
6 const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
7 const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
9 const MUL_A: (u32, bool) = 5u32.overflowing_mul(2);
10 const MUL_B: (u32, bool) = 1_000_000_000u32.overflowing_mul(10);
12 const SHL_A: (u32, bool) = 0x1u32.overflowing_shl(4);
13 const SHL_B: (u32, bool) = 0x1u32.overflowing_shl(132);
15 const SHR_A: (u32, bool) = 0x10u32.overflowing_shr(4);
16 const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
18 fn ident<T>(ident: T) -> T {
23 assert_eq!(ADD_A, ident((7, false)));
24 assert_eq!(ADD_B, ident((0, true)));
26 assert_eq!(SUB_A, ident((3, false)));
27 assert_eq!(SUB_B, ident((u32::max_value(), true)));
29 assert_eq!(MUL_A, ident((10, false)));
30 assert_eq!(MUL_B, ident((1410065408, true)));
32 assert_eq!(SHL_A, ident((0x10, false)));
33 assert_eq!(SHL_B, ident((0x10, true)));
35 assert_eq!(SHR_A, ident((0x1, false)));
36 assert_eq!(SHR_B, ident((0x1, true)));