Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7861121

Browse files
committed
Add naive remainder impl to Saturating
1 parent 3f7d2ce commit 7861121

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

library/core/src/num/saturating.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::fmt;
44
use crate::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign};
55
use crate::ops::{BitXor, BitXorAssign, Div, DivAssign};
6-
use crate::ops::{Mul, MulAssign, Neg, Not};
6+
use crate::ops::{Mul, MulAssign, Neg, Not, Rem, RemAssign};
77
use crate::ops::{Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign};
88

99
/// Provides intentionally-wrapped arithmetic on `T`.
@@ -288,6 +288,27 @@ macro_rules! saturating_impl {
288288
}
289289
forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> }
290290

291+
#[unstable(feature = "saturating_int_impl", issue = "87920")]
292+
impl Rem for Saturating<$t> {
293+
type Output = Saturating<$t>;
294+
295+
#[inline]
296+
fn rem(self, other: Saturating<$t>) -> Saturating<$t> {
297+
Saturating(self.0.rem(other.0))
298+
}
299+
}
300+
forward_ref_binop! { impl Rem, rem for Saturating<$t>, Saturating<$t>,
301+
#[unstable(feature = "saturating_int_impl", issue = "87920")] }
302+
303+
#[unstable(feature = "saturating_int_impl", issue = "87920")]
304+
impl RemAssign for Saturating<$t> {
305+
#[inline]
306+
fn rem_assign(&mut self, other: Saturating<$t>) {
307+
*self = *self % other;
308+
}
309+
}
310+
forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t> }
311+
291312
#[unstable(feature = "saturating_int_impl", issue = "87920")]
292313
impl Not for Saturating<$t> {
293314
type Output = Saturating<$t>;

0 commit comments

Comments
 (0)