Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bit_manipulation/binary_count_trailing_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn binary_count_trailing_zeros_bitwise(num: u64) -> u32 {
return 0;
}

let rightmost_set_bit = num & (num.wrapping_neg());
let rightmost_set_bit = num.isolate_lowest_one();
rightmost_set_bit.ilog2()
}

Expand Down
4 changes: 2 additions & 2 deletions src/bit_manipulation/rightmost_set_bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn index_of_rightmost_set_bit(num: i32) -> Result<u32, String> {
}

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

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

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

// Use f64 log2 and convert to position
let position = (rightmost_bit as f64).log2() as u32 + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/financial/exponential_moving_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn exponential_moving_average(
if i == 0 {
stock_price
} else {
(*moving_average + stock_price) * 0.5
f64::midpoint(*moving_average, stock_price)
}
} else {
// Apply exponential smoothing formula
Expand Down
2 changes: 1 addition & 1 deletion src/hashing/md5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn md5(input: &[u8]) -> [u8; 16] {
msg.extend_from_slice(&bit_len.to_le_bytes());

// --- Processing: 512-bit (64-byte) chunks ---
for chunk in msg.chunks_exact(64) {
for chunk in msg.as_chunks::<64>().0 {
// Break chunk into 16 little-endian 32-bit words
let mut m = [0u32; 16];
for (i, word) in m.iter_mut().enumerate() {
Expand Down
8 changes: 4 additions & 4 deletions src/hashing/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ fn sha256_compress(state: &mut [u32; 8], block: &[u8; 64]) {

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

fn sha512_hash(msg: &[u8], mut state: [u64; 8]) -> [u64; 8] {
let padded = sha512_pad(msg);
for chunk in padded.chunks_exact(128) {
sha512_compress(&mut state, chunk.try_into().unwrap());
for chunk in padded.as_chunks::<128>().0 {
sha512_compress(&mut state, chunk);
}
state
}
Expand Down
2 changes: 1 addition & 1 deletion src/math/trapezoidal_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ where
let left_side = a + (delta * trapezoid as f64);
let right_side = left_side + delta;

0.5 * (f(left_side) + f(right_side)) * delta
f64::midpoint(f(left_side), f(right_side)) * delta
})
.sum()
}
Expand Down