How to get an absolute value in Rust?
Rust does support a function calledabs()
which returns an absolute value.Example of absolute value in Rust
fn main() {
let value = -42i32;
let x = value.abs();
println!("value is {}", value);
println!("x is {}", x);
}
Output
value is -42
x is 42
x is 42