Skip to content

Commit bd6ae45

Browse files
authored
RemMixed implementation for even splits (#791)
When the `RemMixed` trait was added in #746 I missed that we need an impl for even splits as well. This rectifies that mistake.
1 parent a52bdda commit bd6ae45

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ _The below list is very much incomplete._
2222

2323
### Changed
2424
- Make `as_limbs_mut` const ([#757])
25+
- Impl `RemMixed` for even splits as well ([#791])
2526
- Make `Integer` be fmt::Binary, LowerHex and UpperHex ([#792])
26-
27+
-
2728
[#757]: https://github.com/RustCrypto/crypto-bigint/pull/757
2829
[#760]: https://github.com/RustCrypto/crypto-bigint/pull/760
29-
[#792]: https://github.com/RustCrypto/crypto-bigint/pull/792
30+
[#791]: https://github.com/RustCrypto/crypto-bigint/pull/791
31+
[#792]:https://github.com/RustCrypto/crypto-bigint/pull/792
3032

3133
## 0.6.0 (2025-01-22)
3234
### Added

src/uint/div.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ impl<const LIMBS: usize> RemLimb for Uint<LIMBS> {
11141114
#[cfg(test)]
11151115
mod tests {
11161116
use crate::{
1117-
DivVartime, Limb, NonZero, RemMixed, U64, U128, U256, U896, U1024, Uint, Word, Zero,
1117+
DivVartime, Limb, NonZero, RemMixed, U64, U128, U256, U512, U896, U1024, Uint, Word, Zero,
11181118
};
11191119

11201120
#[cfg(feature = "rand")]
@@ -1391,6 +1391,29 @@ mod tests {
13911391
);
13921392
}
13931393

1394+
#[test]
1395+
fn rem_mixed_even() {
1396+
let x = U1024::from_be_hex(concat![
1397+
"3740C11DB8F260753BC6B97DD2B8746D3E2694412772AC6ABD975119EE0A6190",
1398+
"F27F6F0969BCA069D8D151031AF83EE2283CC2E3E4FADBBDB9EEDBF0B8F4C1FD",
1399+
"51912C0D329FDC37D49176DB0A1A2D17E5E6D4F9F6B217FE9412EAA2F881F702",
1400+
"7A831C1B06D31D3618D218D6E667DBD85BFC7B6B6B93422D52516989376AA29A",
1401+
]);
1402+
let y = U512::from_u64(1234567890987654321);
1403+
let rem: U512 = x.rem_mixed(&y.to_nz().unwrap());
1404+
1405+
let y_wide = U512::concat_mixed(&y, &U512::ZERO);
1406+
let rem_control: U1024 = x.rem(&NonZero::new(y_wide).unwrap());
1407+
1408+
assert_eq!(rem.bits(), rem_control.bits());
1409+
assert_eq!(rem.as_words(), &rem_control.as_words()[0..U512::LIMBS]);
1410+
assert!(
1411+
rem_control.as_words()[U512::LIMBS..]
1412+
.iter()
1413+
.all(|w| *w == 0)
1414+
);
1415+
}
1416+
13941417
#[test]
13951418
fn rem_mixed_through_traits() {
13961419
struct A<T, U> {

src/uint/macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ macro_rules! impl_uint_concat_split_even {
102102
}
103103
}
104104

105+
impl $crate::traits::RemMixed<Uint<{ <$name>::LIMBS / 2 }>> for $name
106+
{
107+
fn rem_mixed(&self, reductor: &NonZero<Uint<{ <$name>::LIMBS / 2 }>>) -> Uint<{ <$name>::LIMBS / 2 }> {
108+
self.div_rem_vartime(reductor).1
109+
}
110+
}
111+
105112
impl $crate::traits::Split for $name
106113
{
107114
type Output = Uint<{ <$name>::LIMBS / 2 }>;

0 commit comments

Comments
 (0)