Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Integer-overflow/Rust/integer-overflow-1.rust
Normal file
13
Task/Integer-overflow/Rust/integer-overflow-1.rust
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// The following will panic!
|
||||
let i32_1 : i32 = -(-2_147_483_647 - 1);
|
||||
let i32_2 : i32 = 2_000_000_000 + 2_000_000_000;
|
||||
let i32_3 : i32 = -2_147_483_647 - 2_147_483_647;
|
||||
let i32_4 : i32 = 46341 * 46341;
|
||||
let i32_5 : i32 = (-2_147_483_647 - 1) / -1;
|
||||
|
||||
// These will panic! also
|
||||
let i64_1 : i64 = -(-9_223_372_036_854_775_807 - 1);
|
||||
let i64_2 : i64 = 5_000_000_000_000_000_000 + 5_000_000_000_000_000_000;
|
||||
let i64_3 : i64 = -9_223_372_036_854_775_807 - 9_223_372_036_854_775_807;
|
||||
let i64_4 : i64 = 3_037_000_500 * 3_037_000_500;
|
||||
let i64_5 : i64 = (-9_223_372_036_854_775_807 - 1) / -1;
|
||||
9
Task/Integer-overflow/Rust/integer-overflow-2.rust
Normal file
9
Task/Integer-overflow/Rust/integer-overflow-2.rust
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// The following will never panic!
|
||||
println!("{:?}", 65_537u32.checked_mul(65_537)); // None
|
||||
println!("{:?}", 65_537u32.saturating_mul(65_537)); // 4294967295
|
||||
println!("{:?}", 65_537u32.wrapping_mul(65_537)); // 131073
|
||||
|
||||
// These will never panic! either
|
||||
println!("{:?}", 65_537i32.checked_mul(65_537)); // None
|
||||
println!("{:?}", 65_537i32.saturating_mul(65_537)); // 2147483647
|
||||
println!("{:?}", 65_537i32.wrapping_mul(-65_537)); // -131073
|
||||
Loading…
Add table
Add a link
Reference in a new issue