std-method
Signed unsigned_abs and abs_diff
Represent magnitudes and distances in the corresponding unsigned type, including the extreme signed endpoints. Expected stdout (not executed): 2147483648 4294967295 Common mistake: Subtracting signed endpoints first, which can overflow before abs.
Formal Syntax & Structure
rust syntaxrust
x.unsigned_abs(); x.abs_diff(y)Working Example
Example Snippetrust
fn main() { println!("{}", i32::MIN.unsigned_abs()); println!("{}", i32::MIN.abs_diff(i32::MAX));}