File tree Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use core::mem;
3
3
use core:: ops:: Shl ;
4
4
use num_traits:: One ;
5
5
6
- use crate :: big_digit:: { self , BigDigit , DoubleBigDigit , SignedDoubleBigDigit } ;
6
+ use crate :: big_digit:: { self , BigDigit , DoubleBigDigit } ;
7
7
use crate :: biguint:: BigUint ;
8
8
9
9
struct MontyReducer {
@@ -15,16 +15,17 @@ struct MontyReducer {
15
15
fn inv_mod_alt ( b : BigDigit ) -> BigDigit {
16
16
assert_ne ! ( b & 1 , 0 ) ;
17
17
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 ;
20
20
let mut i = 1 ;
21
21
while i < big_digit:: BITS {
22
22
t = t. wrapping_mul ( t) ;
23
23
k0 = k0. wrapping_mul ( t + 1 ) ;
24
24
25
25
i <<= 1 ;
26
26
}
27
- -k0 as BigDigit
27
+ debug_assert_eq ! ( k0. wrapping_mul( b) , 1 ) ;
28
+ k0. wrapping_neg ( )
28
29
}
29
30
30
31
impl MontyReducer {
Original file line number Diff line number Diff line change @@ -238,12 +238,6 @@ mod big_digit {
238
238
pub ( crate ) type DoubleBigDigit = u128 ;
239
239
) ;
240
240
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
-
247
241
pub ( crate ) const BITS : u8 = BigDigit :: BITS as u8 ;
248
242
pub ( crate ) const HALF_BITS : u8 = BITS / 2 ;
249
243
pub ( crate ) const HALF : BigDigit = ( 1 << HALF_BITS ) - 1 ;
You can’t perform that action at this time.
0 commit comments