@@ -2189,6 +2189,45 @@ macro_rules! int_impl {
21892189 }
21902190 }
21912191
2192+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
2193+ ///
2194+ /// # Panics
2195+ ///
2196+ /// This function will panic if `rhs` is zero.
2197+ ///
2198+ /// ## Overflow behavior
2199+ ///
2200+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2201+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2202+ ///
2203+ /// # Examples
2204+ ///
2205+ /// Basic usage:
2206+ ///
2207+ /// ```
2208+ /// #![feature(int_roundings)]
2209+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2210+ /// let b = 3;
2211+ ///
2212+ /// assert_eq!(a.rem_floor(b), 2);
2213+ /// assert_eq!(a.rem_floor(-b), -1);
2214+ /// assert_eq!((-a).rem_floor(b), 1);
2215+ /// assert_eq!((-a).rem_floor(-b), -2);
2216+ /// ```
2217+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
2218+ #[ must_use = "this returns the result of the operation, \
2219+ without modifying the original"]
2220+ #[ inline]
2221+ #[ rustc_inherit_overflow_checks]
2222+ pub const fn rem_floor( self , rhs: Self ) -> Self {
2223+ let r = self % rhs;
2224+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2225+ r + rhs
2226+ } else {
2227+ r
2228+ }
2229+ }
2230+
21922231 /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
21932232 ///
21942233 /// # Panics
@@ -2229,6 +2268,48 @@ macro_rules! int_impl {
22292268 }
22302269 }
22312270
2271+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
2272+ ///
2273+ /// This operation is *only* available for signed integers,
2274+ /// since the result would be negative if both operands are positive.
2275+ ///
2276+ /// # Panics
2277+ ///
2278+ /// This function will panic if `rhs` is zero.
2279+ ///
2280+ /// ## Overflow behavior
2281+ ///
2282+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2283+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2284+ ///
2285+ /// # Examples
2286+ ///
2287+ /// Basic usage:
2288+ ///
2289+ /// ```
2290+ /// #![feature(rem_ceil)]
2291+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2292+ /// let b = 3;
2293+ ///
2294+ /// assert_eq!(a.rem_ceil(b), -1);
2295+ /// assert_eq!(a.rem_ceil(-b), 2);
2296+ /// assert_eq!((-a).rem_ceil(b), -2);
2297+ /// assert_eq!((-a).rem_ceil(-b), 1);
2298+ /// ```
2299+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
2300+ #[ must_use = "this returns the result of the operation, \
2301+ without modifying the original"]
2302+ #[ inline]
2303+ #[ rustc_inherit_overflow_checks]
2304+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
2305+ let r = self % rhs;
2306+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
2307+ r - rhs
2308+ } else {
2309+ r
2310+ }
2311+ }
2312+
22322313 /// If `rhs` is positive, calculates the smallest value greater than or
22332314 /// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
22342315 /// calculates the largest value less than or equal to `self` that is a
0 commit comments