Skip to content

Commit

Permalink
Add method BigDecimalRef::count_trailing_zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Oct 28, 2024
1 parent e94bdaf commit bcf065a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,19 @@ impl BigDecimalRef<'_> {
count_decimal_digits_uint(self.digits)
}

/// Return the number of trailing zeros in the referenced integer
#[allow(dead_code)]
fn count_trailing_zeroes(&self) -> usize {
if self.digits.is_zero() || self.digits.is_odd() {
return 0;
}

let digit_pairs = self.digits.to_radix_le(100);
let loc = digit_pairs.iter().position(|&d| d != 0).unwrap_or(0);

2 * loc + usize::from(digit_pairs[loc] % 10 == 0)
}

/// Split into components
pub(crate) fn as_parts(&self) -> (Sign, i64, &BigUint) {
(self.sign, self.scale, self.digits)
Expand Down

0 comments on commit bcf065a

Please sign in to comment.