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