@@ -40,6 +40,21 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
4040 /// Computes the absolute difference between `self` and `other`.
4141 fn abs_diff ( self , other : Self ) -> Self ;
4242
43+ /// Calculates `self` − `rhs` − `borrow` and returns a tuple
44+ /// containing the difference and the output borrow.
45+ fn borrowing_sub ( self , rhs : Self , borrow : bool ) -> ( Self , bool ) ;
46+
47+ /// Calculates `self` + `rhs` + `carry` and returns a tuple containing
48+ /// the sum and the output carry (in that order).
49+ fn carrying_add ( self , rhs : Self , carry : bool ) -> ( Self , bool ) ;
50+
51+ /// Calculates the "full multiplication" `self * rhs + carry`
52+ /// without the possibility to overflow.
53+ fn carrying_mul ( self , rhs : Self , carry : Self ) -> ( Self , Self ) ;
54+
55+ /// Calculates the "full multiplication" `self * rhs + carry + add`.
56+ fn carrying_mul_add ( self , rhs : Self , carry : Self , add : Self ) -> ( Self , Self ) ;
57+
4358 /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
4459 fn cast_signed ( self ) -> Self :: Signed ;
4560
@@ -56,6 +71,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
5671 /// wrapped in Some.
5772 fn checked_next_power_of_two ( self ) -> Option < Self > ;
5873
74+ /// Checked integer subtraction. Computes `self - rhs` and checks if the result fits into a
75+ /// signed integer of the same size, returning `None` if overflow occurred.
76+ fn checked_signed_diff ( self , rhs : Self ) -> Option < Self :: Signed > ;
77+
5978 /// Checked subtraction with a signed integer. Computes `self - rhs`,
6079 /// returning `None` if overflow occurred.
6180 fn checked_sub_signed ( self , rhs : Self :: Signed ) -> Option < Self > ;
@@ -91,6 +110,14 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
91110 /// the numeric bounds instead of overflowing.
92111 fn saturating_sub_signed ( self , rhs : Self :: Signed ) -> Self ;
93112
113+ /// Strict addition with a signed integer. Computes `self + rhs`,
114+ /// panicking if overflow occurred.
115+ fn strict_add_signed ( self , rhs : Self :: Signed ) -> Self ;
116+
117+ /// Strict subtraction with a signed integer. Computes `self - rhs`,
118+ /// panicking if overflow occurred.
119+ fn strict_sub_signed ( self , rhs : Self :: Signed ) -> Self ;
120+
94121 /// Wrapping (modular) addition with a signed integer. Computes `self + rhs`, wrapping around
95122 /// at the boundary of the type.
96123 fn wrapping_add_signed ( self , rhs : Self :: Signed ) -> Self ;
@@ -113,10 +140,15 @@ macro_rules! impl_unsigned {
113140
114141 forward! {
115142 fn abs_diff( self , other: Self ) -> Self ;
143+ fn borrowing_sub( self , rhs: Self , borrow: bool ) -> ( Self , bool ) ;
144+ fn carrying_add( self , rhs: Self , carry: bool ) -> ( Self , bool ) ;
145+ fn carrying_mul( self , rhs: Self , carry: Self ) -> ( Self , Self ) ;
146+ fn carrying_mul_add( self , rhs: Self , carry: Self , add: Self ) -> ( Self , Self ) ;
116147 fn cast_signed( self ) -> Self :: Signed ;
117148 fn checked_add_signed( self , rhs: Self :: Signed ) -> Option <Self >;
118149 fn checked_next_multiple_of( self , rhs: Self ) -> Option <Self >;
119150 fn checked_next_power_of_two( self ) -> Option <Self >;
151+ fn checked_signed_diff( self , rhs: Self ) -> Option <Self :: Signed >;
120152 fn checked_sub_signed( self , rhs: Self :: Signed ) -> Option <Self >;
121153 fn div_ceil( self , rhs: Self ) -> Self ;
122154 fn is_multiple_of( self , rhs: Self ) -> bool ;
@@ -127,6 +159,8 @@ macro_rules! impl_unsigned {
127159 fn overflowing_sub_signed( self , rhs: Self :: Signed ) -> ( Self , bool ) ;
128160 fn saturating_add_signed( self , rhs: Self :: Signed ) -> Self ;
129161 fn saturating_sub_signed( self , rhs: Self :: Signed ) -> Self ;
162+ fn strict_add_signed( self , rhs: Self :: Signed ) -> Self ;
163+ fn strict_sub_signed( self , rhs: Self :: Signed ) -> Self ;
130164 fn wrapping_add_signed( self , rhs: Self :: Signed ) -> Self ;
131165 fn wrapping_sub_signed( self , rhs: Self :: Signed ) -> Self ;
132166 }
0 commit comments