std-method

Signed saturating_abs and saturating_neg

For signed magnitudes, deliberately approximate the unrepresentable positive endpoint with the maximum value. Expected stdout (not executed): 2147483647 2147483647 Common mistake: Treating the saturated answer as the exact mathematical magnitude.

Formal Syntax & Structure

rust syntaxrust
x.saturating_abs(); x.saturating_neg()

Working Example

Example Snippetrust
fn main() {    println!("{} {}", i32::MIN.saturating_abs(), i32::MIN.saturating_neg());}
Rust Reference