2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-01 08:05:55 -05:00
|
|
|
const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
|
2020-06-02 02:59:11 -05:00
|
|
|
const ADD_B: (u32, bool) = u32::MAX.overflowing_add(1);
|
2018-09-01 08:05:55 -05:00
|
|
|
|
|
|
|
const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
|
|
|
|
const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
|
|
|
|
|
|
|
|
const MUL_A: (u32, bool) = 5u32.overflowing_mul(2);
|
|
|
|
const MUL_B: (u32, bool) = 1_000_000_000u32.overflowing_mul(10);
|
|
|
|
|
|
|
|
const SHL_A: (u32, bool) = 0x1u32.overflowing_shl(4);
|
|
|
|
const SHL_B: (u32, bool) = 0x1u32.overflowing_shl(132);
|
|
|
|
|
|
|
|
const SHR_A: (u32, bool) = 0x10u32.overflowing_shr(4);
|
|
|
|
const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
|
|
|
|
|
2019-02-01 21:07:26 -06:00
|
|
|
const NEG_A: (u32, bool) = 0u32.overflowing_neg();
|
2020-10-24 18:21:40 -05:00
|
|
|
const NEG_B: (u32, bool) = u32::MAX.overflowing_neg();
|
2019-02-01 19:50:21 -06:00
|
|
|
|
2019-08-21 08:40:12 -05:00
|
|
|
const ABS_POS: (i32, bool) = 10i32.overflowing_abs();
|
|
|
|
const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs();
|
2020-06-02 02:59:11 -05:00
|
|
|
const ABS_MIN: (i32, bool) = i32::MIN.overflowing_abs();
|
2019-08-21 08:40:12 -05:00
|
|
|
|
2018-09-01 08:05:55 -05:00
|
|
|
fn main() {
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(ADD_A, (7, false));
|
|
|
|
assert_eq!(ADD_B, (0, true));
|
2018-09-01 08:05:55 -05:00
|
|
|
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(SUB_A, (3, false));
|
2020-06-02 02:59:11 -05:00
|
|
|
assert_eq!(SUB_B, (u32::MAX, true));
|
2018-09-01 08:05:55 -05:00
|
|
|
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(MUL_A, (10, false));
|
|
|
|
assert_eq!(MUL_B, (1410065408, true));
|
2018-09-01 08:05:55 -05:00
|
|
|
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(SHL_A, (0x10, false));
|
|
|
|
assert_eq!(SHL_B, (0x10, true));
|
2018-09-01 08:05:55 -05:00
|
|
|
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(SHR_A, (0x1, false));
|
|
|
|
assert_eq!(SHR_B, (0x1, true));
|
2019-02-01 19:50:21 -06:00
|
|
|
|
2019-06-08 05:30:52 -05:00
|
|
|
assert_eq!(NEG_A, (0, false));
|
|
|
|
assert_eq!(NEG_B, (1, true));
|
2019-08-21 08:40:12 -05:00
|
|
|
|
|
|
|
assert_eq!(ABS_POS, (10, false));
|
|
|
|
assert_eq!(ABS_NEG, (10, false));
|
2020-06-02 02:59:11 -05:00
|
|
|
assert_eq!(ABS_MIN, (i32::MIN, true));
|
2018-09-01 08:05:55 -05:00
|
|
|
}
|