You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #93873 - Stovent:big-ints, r=m-ou-se
Reimplement `carrying_add` and `borrowing_sub` for signed integers.
As per the discussion in #85532, this PR reimplements `carrying_add` and `borrowing_sub` for signed integers.
It also adds unit tests for both unsigned and signed integers, emphasing on the behaviours of the methods.
// note: longer-term this should be done via an intrinsic.
1560
+
// note: no intermediate overflow is required (https://github.com/rust-lang/rust/issues/85532#issuecomment-1032214946).
1561
+
let(a, b) = self.overflowing_add(rhs);
1562
+
let(c, d) = a.overflowing_add(carry as $SelfT);
1563
+
(c, b != d)
1564
+
}
1565
+
1521
1566
/// Calculates `self` + `rhs` with an unsigned `rhs`
1522
1567
///
1523
1568
/// Returns a tuple of the addition along with a boolean indicating
@@ -1569,6 +1614,39 @@ macro_rules! int_impl {
1569
1614
(a asSelf, b)
1570
1615
}
1571
1616
1617
+
/// Calculates `self - rhs - borrow` without the ability to overflow.
1618
+
///
1619
+
/// Performs "signed ternary subtraction" which takes in an extra bit to subtract, and may return an
1620
+
/// additional bit of overflow. This signed function is used only on the highest-ordered data,
1621
+
/// for which the signed overflow result indicates whether the big integer overflowed or not.
// note: longer-term this should be done via an intrinsic.
1644
+
// note: no intermediate overflow is required (https://github.com/rust-lang/rust/issues/85532#issuecomment-1032214946).
1645
+
let(a, b) = self.overflowing_sub(rhs);
1646
+
let(c, d) = a.overflowing_sub(borrow as $SelfT);
1647
+
(c, b != d)
1648
+
}
1649
+
1572
1650
/// Calculates `self` - `rhs` with an unsigned `rhs`
1573
1651
///
1574
1652
/// Returns a tuple of the subtraction along with a boolean indicating
0 commit comments