@@ -74,14 +74,15 @@ impl<const L: usize> Shr<u32> for &LInt<L> {
74
74
"Cannot shift by 0 or more than 63 bits!"
75
75
) ;
76
76
let ( mut data, right) = ( [ 0 ; L ] , u64:: BITS - bits) ;
77
- for i in 0 ..( L - 1 ) {
78
- data[ i] = ( self . 0 [ i] >> bits) | ( self . 0 [ i + 1 ] << right) ;
77
+
78
+ for ( i, d) in data. iter_mut ( ) . enumerate ( ) . take ( L - 1 ) {
79
+ * d = ( self . 0 [ i] >> bits) | ( self . 0 [ i + 1 ] << right) ;
79
80
}
80
81
data[ L - 1 ] = self . 0 [ L - 1 ] >> bits;
81
82
if self . is_negative ( ) {
82
83
data[ L - 1 ] |= u64:: MAX << right;
83
84
}
84
- Self :: Output { 0 : data }
85
+ LInt :: < L > ( data)
85
86
}
86
87
}
87
88
@@ -96,10 +97,10 @@ impl<const L: usize> Add for &LInt<L> {
96
97
type Output = LInt < L > ;
97
98
fn add ( self , other : Self ) -> Self :: Output {
98
99
let ( mut data, mut carry) = ( [ 0 ; L ] , false ) ;
99
- for i in 0 .. L {
100
- ( data [ i ] , carry) = Self :: Output :: sum ( self . 0 [ i] , other. 0 [ i] , carry) ;
100
+ for ( i , d ) in data . iter_mut ( ) . enumerate ( ) . take ( L ) {
101
+ ( * d , carry) = Self :: Output :: sum ( self . 0 [ i] , other. 0 [ i] , carry) ;
101
102
}
102
- Self :: Output { 0 : data }
103
+ LInt :: < L > ( data)
103
104
}
104
105
}
105
106
@@ -128,10 +129,10 @@ impl<const L: usize> Sub for &LInt<L> {
128
129
// addition algorithm, where the carry flag is initialized with "true"
129
130
// and the chunks of the second argument are bitwise inverted
130
131
let ( mut data, mut carry) = ( [ 0 ; L ] , true ) ;
131
- for i in 0 .. L {
132
- ( data [ i ] , carry) = Self :: Output :: sum ( self . 0 [ i] , !other. 0 [ i] , carry) ;
132
+ for ( i , d ) in data . iter_mut ( ) . enumerate ( ) . take ( L ) {
133
+ ( * d , carry) = Self :: Output :: sum ( self . 0 [ i] , !other. 0 [ i] , carry) ;
133
134
}
134
- Self :: Output { 0 : data }
135
+ LInt :: < L > ( data)
135
136
}
136
137
}
137
138
@@ -155,10 +156,10 @@ impl<const L: usize> Neg for &LInt<L> {
155
156
// For the two's complement code the additive negation is the result
156
157
// of adding 1 to the bitwise inverted argument's representation
157
158
let ( mut data, mut carry) = ( [ 0 ; L ] , true ) ;
158
- for i in 0 .. L {
159
- ( data [ i ] , carry) = ( !self . 0 [ i] ) . overflowing_add ( carry as u64 ) ;
159
+ for ( i , d ) in data . iter_mut ( ) . enumerate ( ) . take ( L ) {
160
+ ( * d , carry) = ( !self . 0 [ i] ) . overflowing_add ( carry as u64 ) ;
160
161
}
161
- Self :: Output { 0 : data }
162
+ LInt :: < L > ( data)
162
163
}
163
164
}
164
165
@@ -180,7 +181,7 @@ impl<const L: usize> Mul for &LInt<L> {
180
181
Self :: Output :: prodsum ( self . 0 [ i] , other. 0 [ k] , data[ i + k] , carry) ;
181
182
}
182
183
}
183
- Self :: Output { 0 : data }
184
+ LInt :: < L > ( data)
184
185
}
185
186
}
186
187
@@ -219,11 +220,10 @@ impl<const L: usize> Mul<i64> for &LInt<L> {
219
220
} else {
220
221
( other as u64 , 0 , 0 )
221
222
} ;
222
- #[ allow( clippy:: needless_range_loop) ]
223
- for i in 0 ..L {
224
- ( data[ i] , carry) = Self :: Output :: prodsum ( self . 0 [ i] ^ mask, other, 0 , carry) ;
223
+ for ( i, d) in data. iter_mut ( ) . enumerate ( ) . take ( L ) {
224
+ ( * d, carry) = Self :: Output :: prodsum ( self . 0 [ i] ^ mask, other, 0 , carry) ;
225
225
}
226
- Self :: Output { 0 : data }
226
+ LInt :: < L > ( data)
227
227
}
228
228
}
229
229
0 commit comments