@@ -3030,6 +3030,45 @@ macro_rules! int_impl {
3030
3030
}
3031
3031
}
3032
3032
3033
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
3034
+ ///
3035
+ /// # Panics
3036
+ ///
3037
+ /// This function will panic if `rhs` is zero.
3038
+ ///
3039
+ /// ## Overflow behavior
3040
+ ///
3041
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
3042
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
3043
+ ///
3044
+ /// # Examples
3045
+ ///
3046
+ /// Basic usage:
3047
+ ///
3048
+ /// ```
3049
+ /// #![feature(int_roundings)]
3050
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
3051
+ /// let b = 3;
3052
+ ///
3053
+ /// assert_eq!(a.rem_floor(b), 2);
3054
+ /// assert_eq!(a.rem_floor(-b), -1);
3055
+ /// assert_eq!((-a).rem_floor(b), 1);
3056
+ /// assert_eq!((-a).rem_floor(-b), -2);
3057
+ /// ```
3058
+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
3059
+ #[ must_use = "this returns the result of the operation, \
3060
+ without modifying the original"]
3061
+ #[ inline]
3062
+ #[ rustc_inherit_overflow_checks]
3063
+ pub const fn rem_floor( self , rhs: Self ) -> Self {
3064
+ let r = self % rhs;
3065
+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
3066
+ r + rhs
3067
+ } else {
3068
+ r
3069
+ }
3070
+ }
3071
+
3033
3072
/// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
3034
3073
///
3035
3074
/// # Panics
@@ -3066,6 +3105,48 @@ macro_rules! int_impl {
3066
3105
}
3067
3106
}
3068
3107
3108
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
3109
+ ///
3110
+ /// This operation is *only* available for signed integers,
3111
+ /// since the result would be negative if both operands are positive.
3112
+ ///
3113
+ /// # Panics
3114
+ ///
3115
+ /// This function will panic if `rhs` is zero.
3116
+ ///
3117
+ /// ## Overflow behavior
3118
+ ///
3119
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
3120
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
3121
+ ///
3122
+ /// # Examples
3123
+ ///
3124
+ /// Basic usage:
3125
+ ///
3126
+ /// ```
3127
+ /// #![feature(rem_ceil)]
3128
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
3129
+ /// let b = 3;
3130
+ ///
3131
+ /// assert_eq!(a.rem_ceil(b), -1);
3132
+ /// assert_eq!(a.rem_ceil(-b), 2);
3133
+ /// assert_eq!((-a).rem_ceil(b), -2);
3134
+ /// assert_eq!((-a).rem_ceil(-b), 1);
3135
+ /// ```
3136
+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
3137
+ #[ must_use = "this returns the result of the operation, \
3138
+ without modifying the original"]
3139
+ #[ inline]
3140
+ #[ rustc_inherit_overflow_checks]
3141
+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
3142
+ let r = self % rhs;
3143
+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
3144
+ r - rhs
3145
+ } else {
3146
+ r
3147
+ }
3148
+ }
3149
+
3069
3150
/// If `rhs` is positive, calculates the smallest value greater than or
3070
3151
/// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
3071
3152
/// calculates the largest value less than or equal to `self` that is a
0 commit comments