2 ms·
Rust offers: * i8::MIN.checked_abs() is None * i8::MIN.overflowing_abs() is (i8::MIN,true) * i8::MIN.saturating_abs() is i8::MAX * i8::MIN.wrapping_abs() is
by tialaramex 5y ago
Rust offers:
* i8::MIN.checked_abs() is None
* i8::MIN.overflowing_abs() is (i8::MIN,true)
* i8::MIN.saturating_abs() is i8::MAX
* i8::MIN.wrapping_abs() is i8::MIN
[edited to add]
* i8::MIN.unsigned_abs() is the 8-bit unsigned value 128
and finally
* i8::MIN.abs() will panic in debug builds or give i8::MIN in non-debug builds.
You should obviously not choose this last option if you in fact will call this function on i8::MIN (or any similar minimum values) which is why it panics if that happens. You should have instead chosen which behaviour you wanted (checked, overflowing, saturating or wrapping) up front.