Skip to content

Commit 2345c66

Browse files
authored
chore: resolve new clippy warnings (#1066)
1 parent 2c53ddf commit 2345c66

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/bit_manipulation/binary_count_trailing_zeros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn binary_count_trailing_zeros_bitwise(num: u64) -> u32 {
4949
return 0;
5050
}
5151

52-
let rightmost_set_bit = num & (num.wrapping_neg());
52+
let rightmost_set_bit = num.isolate_lowest_one();
5353
rightmost_set_bit.ilog2()
5454
}
5555

src/bit_manipulation/rightmost_set_bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn index_of_rightmost_set_bit(num: i32) -> Result<u32, String> {
4444
}
4545

4646
// Isolate the rightmost set bit using n & -n
47-
let rightmost_bit = num & -num;
47+
let rightmost_bit = num.isolate_lowest_one();
4848

4949
// Calculate position: log2(rightmost_bit) + 1
5050
// We use trailing_zeros which gives us the 0-based position
@@ -72,7 +72,7 @@ pub fn index_of_rightmost_set_bit_log(num: i32) -> Result<u32, String> {
7272
}
7373

7474
// Isolate the rightmost set bit
75-
let rightmost_bit = num & -num;
75+
let rightmost_bit = num.isolate_lowest_one();
7676

7777
// Use f64 log2 and convert to position
7878
let position = (rightmost_bit as f64).log2() as u32 + 1;

src/financial/exponential_moving_average.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn exponential_moving_average(
5050
if i == 0 {
5151
stock_price
5252
} else {
53-
(*moving_average + stock_price) * 0.5
53+
f64::midpoint(*moving_average, stock_price)
5454
}
5555
} else {
5656
// Apply exponential smoothing formula

src/hashing/md5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn md5(input: &[u8]) -> [u8; 16] {
4747
msg.extend_from_slice(&bit_len.to_le_bytes());
4848

4949
// --- Processing: 512-bit (64-byte) chunks ---
50-
for chunk in msg.chunks_exact(64) {
50+
for chunk in msg.as_chunks::<64>().0 {
5151
// Break chunk into 16 little-endian 32-bit words
5252
let mut m = [0u32; 16];
5353
for (i, word) in m.iter_mut().enumerate() {

src/hashing/sha2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ fn sha256_compress(state: &mut [u32; 8], block: &[u8; 64]) {
124124

125125
fn sha256_hash(msg: &[u8], mut state: [u32; 8]) -> [u32; 8] {
126126
let padded = sha256_pad(msg);
127-
for chunk in padded.chunks_exact(64) {
128-
sha256_compress(&mut state, chunk.try_into().unwrap());
127+
for chunk in padded.as_chunks::<64>().0 {
128+
sha256_compress(&mut state, chunk);
129129
}
130130
state
131131
}
@@ -271,8 +271,8 @@ fn sha512_compress(state: &mut [u64; 8], block: &[u8; 128]) {
271271

272272
fn sha512_hash(msg: &[u8], mut state: [u64; 8]) -> [u64; 8] {
273273
let padded = sha512_pad(msg);
274-
for chunk in padded.chunks_exact(128) {
275-
sha512_compress(&mut state, chunk.try_into().unwrap());
274+
for chunk in padded.as_chunks::<128>().0 {
275+
sha512_compress(&mut state, chunk);
276276
}
277277
state
278278
}

src/math/trapezoidal_integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ where
99
let left_side = a + (delta * trapezoid as f64);
1010
let right_side = left_side + delta;
1111

12-
0.5 * (f(left_side) + f(right_side)) * delta
12+
f64::midpoint(f(left_side), f(right_side)) * delta
1313
})
1414
.sum()
1515
}

0 commit comments

Comments
 (0)