@@ -2825,6 +2825,45 @@ macro_rules! int_impl {
28252825 }
28262826 }
28272827
2828+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
2829+ ///
2830+ /// # Panics
2831+ ///
2832+ /// This function will panic if `rhs` is zero.
2833+ ///
2834+ /// ## Overflow behavior
2835+ ///
2836+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2837+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2838+ ///
2839+ /// # Examples
2840+ ///
2841+ /// Basic usage:
2842+ ///
2843+ /// ```
2844+ /// #![feature(int_roundings)]
2845+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2846+ /// let b = 3;
2847+ ///
2848+ /// assert_eq!(a.rem_floor(b), 2);
2849+ /// assert_eq!(a.rem_floor(-b), -1);
2850+ /// assert_eq!((-a).rem_floor(b), 1);
2851+ /// assert_eq!((-a).rem_floor(-b), -2);
2852+ /// ```
2853+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
2854+ #[ must_use = "this returns the result of the operation, \
2855+ without modifying the original"]
2856+ #[ inline]
2857+ #[ rustc_inherit_overflow_checks]
2858+ pub const fn rem_floor( self , rhs: Self ) -> Self {
2859+ let r = self % rhs;
2860+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2861+ r + rhs
2862+ } else {
2863+ r
2864+ }
2865+ }
2866+
28282867 /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
28292868 ///
28302869 /// # Panics
@@ -2861,6 +2900,48 @@ macro_rules! int_impl {
28612900 }
28622901 }
28632902
2903+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
2904+ ///
2905+ /// This operation is *only* available for signed integers,
2906+ /// since the result would be negative if both operands are positive.
2907+ ///
2908+ /// # Panics
2909+ ///
2910+ /// This function will panic if `rhs` is zero.
2911+ ///
2912+ /// ## Overflow behavior
2913+ ///
2914+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2915+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2916+ ///
2917+ /// # Examples
2918+ ///
2919+ /// Basic usage:
2920+ ///
2921+ /// ```
2922+ /// #![feature(rem_ceil)]
2923+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2924+ /// let b = 3;
2925+ ///
2926+ /// assert_eq!(a.rem_ceil(b), -1);
2927+ /// assert_eq!(a.rem_ceil(-b), 2);
2928+ /// assert_eq!((-a).rem_ceil(b), -2);
2929+ /// assert_eq!((-a).rem_ceil(-b), 1);
2930+ /// ```
2931+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
2932+ #[ must_use = "this returns the result of the operation, \
2933+ without modifying the original"]
2934+ #[ inline]
2935+ #[ rustc_inherit_overflow_checks]
2936+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
2937+ let r = self % rhs;
2938+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
2939+ r - rhs
2940+ } else {
2941+ r
2942+ }
2943+ }
2944+
28642945 /// If `rhs` is positive, calculates the smallest value greater than or
28652946 /// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
28662947 /// calculates the largest value less than or equal to `self` that is a
0 commit comments