Skip to content

Commit a135b11

Browse files
committed
feat: add an extra method to (Checked)Euclid trait to get both quotien and rem
1 parent 0a27d8c commit a135b11

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/ops/euclid.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self> {
4646
/// assert_eq!(Euclid::rem_euclid(&-a, &-b), 1);
4747
/// ```
4848
fn rem_euclid(&self, v: &Self) -> Self;
49+
50+
/// Returns both the euclidian division quotien and remainer
51+
///
52+
/// By default, it internaly calls both `Euclid::div_euclid` and `Euclid::rem_euclid`,
53+
/// but it can be overwritten in order to implement some optimization.
54+
fn div_with_rem_euclid(&self, v: &Self) -> (Self, Self) {
55+
(self.div_euclid(v), self.rem_euclid(v))
56+
}
4957
}
5058

5159
macro_rules! euclid_forward_impl {
@@ -174,6 +182,14 @@ pub trait CheckedEuclid: Euclid {
174182
/// Finds the euclid remainder of dividing two numbers, checking for underflow, overflow and
175183
/// division by zero. If any of that happens, `None` is returned.
176184
fn checked_rem_euclid(&self, v: &Self) -> Option<Self>;
185+
186+
/// Returns both the checked euclidian division quotien and remainer
187+
///
188+
/// By default, it internaly calls both `Euclid::div_euclid` and `Euclid::rem_euclid`,
189+
/// but it can be overwritten in order to implement some optimization.
190+
fn checked_div_with_rem_euclid(&self, v: &Self) -> Option<(Self, Self)> {
191+
Some((self.checked_div_euclid(v)?, self.checked_rem_euclid(v)?))
192+
}
177193
}
178194

179195
macro_rules! checked_euclid_forward_impl {

0 commit comments

Comments
 (0)