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;
33use core:: ops:: Shl ;
44use num_traits:: One ;
55
6- use crate :: big_digit:: { self , BigDigit , DoubleBigDigit , SignedDoubleBigDigit } ;
6+ use crate :: big_digit:: { self , BigDigit , DoubleBigDigit } ;
77use crate :: biguint:: BigUint ;
88
99struct MontyReducer {
@@ -15,16 +15,17 @@ struct MontyReducer {
1515fn 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
3031impl MontyReducer {
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments