Skip to content

Commit 98bea13

Browse files
committed
Remove the last use of SignedDoubleBigDigit
The inverse for `MontyReducer` doesn't need a wider type at all!
1 parent d9fb6e6 commit 98bea13

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/biguint/monty.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem;
33
use core::ops::Shl;
44
use num_traits::One;
55

6-
use crate::big_digit::{self, BigDigit, DoubleBigDigit, SignedDoubleBigDigit};
6+
use crate::big_digit::{self, BigDigit, DoubleBigDigit};
77
use crate::biguint::BigUint;
88

99
struct MontyReducer {
@@ -15,16 +15,17 @@ struct MontyReducer {
1515
fn inv_mod_alt(b: BigDigit) -> BigDigit {
1616
assert_ne!(b & 1, 0);
1717

18-
let mut k0 = 2 - b as SignedDoubleBigDigit;
19-
let mut t = (b - 1) as SignedDoubleBigDigit;
18+
let mut k0 = BigDigit::wrapping_sub(2, b);
19+
let mut t = b - 1;
2020
let mut i = 1;
2121
while i < big_digit::BITS {
2222
t = t.wrapping_mul(t);
2323
k0 = k0.wrapping_mul(t + 1);
2424

2525
i <<= 1;
2626
}
27-
-k0 as BigDigit
27+
debug_assert_eq!(k0.wrapping_mul(b), 1);
28+
k0.wrapping_neg()
2829
}
2930

3031
impl MontyReducer {

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,6 @@ mod big_digit {
238238
pub(crate) type DoubleBigDigit = u128;
239239
);
240240

241-
// A [`SignedDoubleBigDigit`] is the signed version of [`DoubleBigDigit`].
242-
cfg_digit!(
243-
pub(crate) type SignedDoubleBigDigit = i64;
244-
pub(crate) type SignedDoubleBigDigit = i128;
245-
);
246-
247241
pub(crate) const BITS: u8 = BigDigit::BITS as u8;
248242
pub(crate) const HALF_BITS: u8 = BITS / 2;
249243
pub(crate) const HALF: BigDigit = (1 << HALF_BITS) - 1;

0 commit comments

Comments
 (0)