@@ -2244,6 +2244,45 @@ macro_rules! int_impl {
2244
2244
}
2245
2245
}
2246
2246
2247
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
2248
+ ///
2249
+ /// # Panics
2250
+ ///
2251
+ /// This function will panic if `rhs` is zero.
2252
+ ///
2253
+ /// ## Overflow behavior
2254
+ ///
2255
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2256
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2257
+ ///
2258
+ /// # Examples
2259
+ ///
2260
+ /// Basic usage:
2261
+ ///
2262
+ /// ```
2263
+ /// #![feature(int_roundings)]
2264
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2265
+ /// let b = 3;
2266
+ ///
2267
+ /// assert_eq!(a.rem_floor(b), 2);
2268
+ /// assert_eq!(a.rem_floor(-b), -1);
2269
+ /// assert_eq!((-a).rem_floor(b), 1);
2270
+ /// assert_eq!((-a).rem_floor(-b), -2);
2271
+ /// ```
2272
+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
2273
+ #[ must_use = "this returns the result of the operation, \
2274
+ without modifying the original"]
2275
+ #[ inline]
2276
+ #[ rustc_inherit_overflow_checks]
2277
+ pub const fn rem_floor( self , rhs: Self ) -> Self {
2278
+ let r = self % rhs;
2279
+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2280
+ r + rhs
2281
+ } else {
2282
+ r
2283
+ }
2284
+ }
2285
+
2247
2286
/// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
2248
2287
///
2249
2288
/// # Panics
@@ -2284,6 +2323,48 @@ macro_rules! int_impl {
2284
2323
}
2285
2324
}
2286
2325
2326
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
2327
+ ///
2328
+ /// This operation is *only* available for signed integers,
2329
+ /// since the result would be negative if both operands are positive.
2330
+ ///
2331
+ /// # Panics
2332
+ ///
2333
+ /// This function will panic if `rhs` is zero.
2334
+ ///
2335
+ /// ## Overflow behavior
2336
+ ///
2337
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2338
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2339
+ ///
2340
+ /// # Examples
2341
+ ///
2342
+ /// Basic usage:
2343
+ ///
2344
+ /// ```
2345
+ /// #![feature(rem_ceil)]
2346
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2347
+ /// let b = 3;
2348
+ ///
2349
+ /// assert_eq!(a.rem_ceil(b), -1);
2350
+ /// assert_eq!(a.rem_ceil(-b), 2);
2351
+ /// assert_eq!((-a).rem_ceil(b), -2);
2352
+ /// assert_eq!((-a).rem_ceil(-b), 1);
2353
+ /// ```
2354
+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
2355
+ #[ must_use = "this returns the result of the operation, \
2356
+ without modifying the original"]
2357
+ #[ inline]
2358
+ #[ rustc_inherit_overflow_checks]
2359
+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
2360
+ let r = self % rhs;
2361
+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
2362
+ r - rhs
2363
+ } else {
2364
+ r
2365
+ }
2366
+ }
2367
+
2287
2368
/// If `rhs` is positive, calculates the smallest value greater than or
2288
2369
/// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
2289
2370
/// calculates the largest value less than or equal to `self` that is a
0 commit comments