rust/src/test/run-pass/consts/const-int-wrapping.rs

38 lines
916 B
Rust
Raw Normal View History

2018-09-01 08:05:55 -05:00
const ADD_A: u32 = 200u32.wrapping_add(55);
const ADD_B: u32 = 200u32.wrapping_add(u32::max_value());
const SUB_A: u32 = 100u32.wrapping_sub(100);
const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value());
const MUL_A: u8 = 10u8.wrapping_mul(12);
const MUL_B: u8 = 25u8.wrapping_mul(12);
const SHL_A: u32 = 1u32.wrapping_shl(7);
const SHL_B: u32 = 1u32.wrapping_shl(128);
const SHR_A: u32 = 128u32.wrapping_shr(7);
const SHR_B: u32 = 128u32.wrapping_shr(128);
2019-02-01 19:55:38 -06:00
const NEG_A: u32 = 5u32.wrapping_neg();
const NEG_B: u32 = 1234567890u32.wrapping_neg();
2018-09-01 08:05:55 -05:00
fn main() {
assert_eq!(ADD_A, 255);
assert_eq!(ADD_B, 199);
2018-09-01 08:05:55 -05:00
assert_eq!(SUB_A, 0);
assert_eq!(SUB_B, 101);
2018-09-01 08:05:55 -05:00
assert_eq!(MUL_A, 120);
assert_eq!(MUL_B, 44);
2018-09-01 08:05:55 -05:00
assert_eq!(SHL_A, 128);
assert_eq!(SHL_B, 1);
2018-09-01 08:05:55 -05:00
assert_eq!(SHR_A, 1);
assert_eq!(SHR_B, 128);
2019-02-01 21:07:26 -06:00
assert_eq!(NEG_A, 4294967291);
assert_eq!(NEG_B, 3060399406);
2018-09-01 08:05:55 -05:00
}