Last active
February 18, 2025 05:05
-
-
Save ssrlive/a03d9825a693ba85843ed35a91117839 to your computer and use it in GitHub Desktop.
Rust digit_overflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn digit_overflow() { | |
assert_eq!(u16::MAX.wrapping_add(9), 8); | |
assert_eq!(u16::MAX.saturating_add(9), u16::MAX); | |
assert_eq!(u16::MAX.checked_add(9), None); | |
assert_eq!(u16::MAX.overflowing_add(9), (8, true)); | |
} | |
#[test] | |
fn digit_overflow_mul() { | |
assert_eq!(u16::MAX.wrapping_mul(9), u16::MAX - 8); | |
assert_eq!(u16::MAX.saturating_mul(9), u16::MAX); | |
assert_eq!(u16::MAX.checked_mul(9), None); | |
assert_eq!(u16::MAX.overflowing_mul(9), (u16::MAX - 8, true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment