Skip to content

Commit cc152c5

Browse files
quaternictgross35
authored andcommitted
clarify impl_narrowing_div_primitive
1 parent 3c02210 commit cc152c5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libm/src/math/support/int_traits/narrowing_div.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::support::{DInt, HInt, Int, MinInt, u256};
1+
use crate::support::{CastInto, DInt, HInt, Int, MinInt, u256};
22

33
/// Trait for unsigned division of a double-wide integer
44
/// when the quotient doesn't overflow.
@@ -25,14 +25,16 @@ pub trait NarrowingDiv: DInt + MinInt<Unsigned = Self> {
2525
}
2626
}
2727

28+
// For primitive types we can just use the standard
29+
// division operators in the double-wide type.
2830
macro_rules! impl_narrowing_div_primitive {
2931
($D:ident) => {
3032
impl NarrowingDiv for $D {
3133
unsafe fn unchecked_narrowing_div_rem(self, n: Self::H) -> (Self::H, Self::H) {
3234
if self.hi() >= n {
3335
unsafe { core::hint::unreachable_unchecked() }
3436
}
35-
((self / n as $D) as Self::H, (self % n as $D) as Self::H)
37+
((self / n.widen()).cast(), (self % n.widen()).cast())
3638
}
3739
}
3840
};

0 commit comments

Comments
 (0)