@@ -2269,6 +2269,45 @@ macro_rules! int_impl {
2269
2269
}
2270
2270
}
2271
2271
2272
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity.
2273
+ ///
2274
+ /// # Panics
2275
+ ///
2276
+ /// This function will panic if `rhs` is zero.
2277
+ ///
2278
+ /// ## Overflow behavior
2279
+ ///
2280
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2281
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2282
+ ///
2283
+ /// # Examples
2284
+ ///
2285
+ /// Basic usage:
2286
+ ///
2287
+ /// ```
2288
+ /// #![feature(int_roundings)]
2289
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2290
+ /// let b = 3;
2291
+ ///
2292
+ /// assert_eq!(a.rem_floor(b), 2);
2293
+ /// assert_eq!(a.rem_floor(-b), -1);
2294
+ /// assert_eq!((-a).rem_floor(b), 1);
2295
+ /// assert_eq!((-a).rem_floor(-b), -2);
2296
+ /// ```
2297
+ #[ unstable( feature = "int_roundings" , issue = "88581" ) ]
2298
+ #[ must_use = "this returns the result of the operation, \
2299
+ without modifying the original"]
2300
+ #[ inline]
2301
+ #[ rustc_inherit_overflow_checks]
2302
+ pub const fn rem_floor( self , rhs: Self ) -> Self {
2303
+ let r = self % rhs;
2304
+ if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2305
+ r + rhs
2306
+ } else {
2307
+ r
2308
+ }
2309
+ }
2310
+
2272
2311
/// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
2273
2312
///
2274
2313
/// # Panics
@@ -2309,6 +2348,48 @@ macro_rules! int_impl {
2309
2348
}
2310
2349
}
2311
2350
2351
+ /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity.
2352
+ ///
2353
+ /// This operation is *only* available for signed integers,
2354
+ /// since the result would be negative if both operands are positive.
2355
+ ///
2356
+ /// # Panics
2357
+ ///
2358
+ /// This function will panic if `rhs` is zero.
2359
+ ///
2360
+ /// ## Overflow behavior
2361
+ ///
2362
+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
2363
+ /// mode) and wrap if overflow checks are disabled (default in release mode).
2364
+ ///
2365
+ /// # Examples
2366
+ ///
2367
+ /// Basic usage:
2368
+ ///
2369
+ /// ```
2370
+ /// #![feature(rem_ceil)]
2371
+ #[ doc = concat!( "let a: " , stringify!( $SelfT) , " = 8;" ) ]
2372
+ /// let b = 3;
2373
+ ///
2374
+ /// assert_eq!(a.rem_ceil(b), -1);
2375
+ /// assert_eq!(a.rem_ceil(-b), 2);
2376
+ /// assert_eq!((-a).rem_ceil(b), -2);
2377
+ /// assert_eq!((-a).rem_ceil(-b), 1);
2378
+ /// ```
2379
+ #[ unstable( feature = "rem_ceil" , issue = "88581" ) ]
2380
+ #[ must_use = "this returns the result of the operation, \
2381
+ without modifying the original"]
2382
+ #[ inline]
2383
+ #[ rustc_inherit_overflow_checks]
2384
+ pub const fn rem_ceil( self , rhs: Self ) -> Self {
2385
+ let r = self % rhs;
2386
+ if ( r > 0 && rhs > 0 ) || ( r < 0 && rhs < 0 ) {
2387
+ r - rhs
2388
+ } else {
2389
+ r
2390
+ }
2391
+ }
2392
+
2312
2393
/// If `rhs` is positive, calculates the smallest value greater than or
2313
2394
/// equal to `self` that is a multiple of `rhs`. If `rhs` is negative,
2314
2395
/// calculates the largest value less than or equal to `self` that is a
0 commit comments