Skip to content

Commit

Permalink
add set_bit to buint
Browse files Browse the repository at this point in the history
  • Loading branch information
krakow10 committed Aug 30, 2024
1 parent d715a3e commit 0c33e0d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/buint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,15 @@ macro_rules! mod_impl {
digit & (1 << (index & digit::$Digit::BITS_MINUS_1)) != 0
}

#[doc = doc::bit!(U 256)]
#[must_use]
#[inline]
pub fn set_bit(&mut self, index: ExpType, value: bool) {
let digit = &mut self.digits[index as usize >> digit::$Digit::BIT_SHIFT];
let shift = index & digit::$Digit::BITS_MINUS_1;
*digit = *digit & (1 << shift) | ($Digit::from(value) << shift)
}

/// Returns an integer whose value is `2^power`. This is faster than using a shift left on `Self::ONE`.
///
/// # Panics
Expand Down

0 comments on commit 0c33e0d

Please sign in to comment.