@@ -2906,6 +2906,45 @@ macro_rules! int_impl {
29062906 }
29072907 }
29082908
2909+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
2910+ ///
2911+ /// # Panics
2912+ ///
2913+ /// This function will panic if `rhs` is zero.
2914+ ///
2915+ /// ## Overflow behavior
2916+ ///
2917+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2918+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2919+ ///
2920+ /// # Examples
2921+ ///
2922+ /// Basic usage:
2923+ ///
2924+ /// ```
2925+ /// #![feature(int_roundings)]
2926+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2927+ /// let b = 3;
2928+ ///
2929+ /// assert_eq!(a.rem_floor(b), 2);
2930+ /// assert_eq!(a.rem_floor(-b), -1);
2931+ /// assert_eq!((-a).rem_floor(b), 1);
2932+ /// assert_eq!((-a).rem_floor(-b), -2);
2933+ /// ```
2934+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
2935+ #[ must_use = "this returns the result of the operation, \
2936+ without modifying the original"]
2937+ #[ inline]
2938+ #[ rustc_inherit_overflow_checks]
2939+ pub const fn rem_floor( self , rhs: Self ) -> Self {
2940+ let r = self % rhs;
2941+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2942+ r + rhs
2943+ } else {
2944+ r
2945+ }
2946+ }
2947+
29092948 /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
29102949 ///
29112950 /// # Panics
@@ -2942,6 +2981,48 @@ macro_rules! int_impl {
29422981 }
29432982 }
29442983
2984+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
2985+ ///
2986+ /// This operation is *only* available for signed integers,
2987+ /// since the result would be negative if both operands are positive.
2988+ ///
2989+ /// # Panics
2990+ ///
2991+ /// This function will panic if `rhs` is zero.
2992+ ///
2993+ /// ## Overflow behavior
2994+ ///
2995+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2996+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2997+ ///
2998+ /// # Examples
2999+ ///
3000+ /// Basic usage:
3001+ ///
3002+ /// ```
3003+ /// #![feature(rem_ceil)]
3004+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
3005+ /// let b = 3;
3006+ ///
3007+ /// assert_eq!(a.rem_ceil(b), -1);
3008+ /// assert_eq!(a.rem_ceil(-b), 2);
3009+ /// assert_eq!((-a).rem_ceil(b), -2);
3010+ /// assert_eq!((-a).rem_ceil(-b), 1);
3011+ /// ```
3012+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
3013+ #[ must_use = "this returns the result of the operation, \
3014+ without modifying the original"]
3015+ #[ inline]
3016+ #[ rustc_inherit_overflow_checks]
3017+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
3018+ let r = self % rhs;
3019+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
3020+ r - rhs
3021+ } else {
3022+ r
3023+ }
3024+ }
3025+
29453026 /// If `rhs` is positive, calculates the smallest value greater than or
29463027 /// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
29473028 /// calculates the largest value less than or equal to `self` that is a
0 commit comments