We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
saturating_add_signed
1 parent 4846fd9 commit 47edde1Copy full SHA for 47edde1
library/core/src/num/uint_macros.rs
@@ -1037,10 +1037,13 @@ macro_rules! uint_impl {
1037
without modifying the original"]
1038
#[inline]
1039
pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self {
1040
- if rhs >= 0 {
1041
- self.saturating_add(rhs as Self)
+ let (res, overflow) = self.overflowing_add(rhs as Self);
+ if overflow == (rhs < 0) {
1042
+ res
1043
+ } else if overflow {
1044
+ Self::MAX
1045
} else {
- self.saturating_sub(rhs.unsigned_abs())
1046
+ 0
1047
}
1048
1049
0 commit comments