std-method

Signed overflowing_neg and overflowing_abs

Receive the wrapped signed value and a flag when the exact magnitude cannot fit. Expected stdout (not executed): (-2147483648, true) (12, false) Common mistake: Ignoring the flag and treating the negative endpoint as a positive magnitude.

Formal Syntax & Structure

rust syntaxrust
n.overflowing_neg(); n.overflowing_abs()

Working Example

Example Snippetrust
fn main() {    println!("{:?}", i32::MIN.overflowing_neg());    println!("{:?}", (-12i32).overflowing_abs());}
Rust Reference