Express `i64::MAX + 1` as `i64::MIN.unsigned_abs()`

This better conveys the intention that we're checking the lower bound.
This commit is contained in:
Martin Habovstiak 2024-01-20 23:44:11 +01:00
parent b562a18914
commit 54cbbf804f
1 changed files with 2 additions and 2 deletions

View File

@ -975,8 +975,8 @@ impl SignedAmount {
// (negative, amount)
(false, sat) if sat > i64::MAX as u64 => Err(ParseAmountError::TooBig),
(false, sat) => Ok(SignedAmount(sat as i64)),
(true, sat) if sat == i64::MAX as u64 + 1 => Ok(SignedAmount(i64::MIN)),
(true, sat) if sat > i64::MAX as u64 + 1 => Err(ParseAmountError::TooBig),
(true, sat) if sat == i64::MIN.unsigned_abs() => Ok(SignedAmount(i64::MIN)),
(true, sat) if sat > i64::MIN.unsigned_abs() => Err(ParseAmountError::TooBig),
(true, sat) => Ok(SignedAmount(-(sat as i64))),
}
}