Skip to content

Commit bcf065a

Browse files
committed
Add method BigDecimalRef::count_trailing_zeroes
1 parent e94bdaf commit bcf065a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,19 @@ impl BigDecimalRef<'_> {
12211221
count_decimal_digits_uint(self.digits)
12221222
}
12231223

1224+
/// Return the number of trailing zeros in the referenced integer
1225+
#[allow(dead_code)]
1226+
fn count_trailing_zeroes(&self) -> usize {
1227+
if self.digits.is_zero() || self.digits.is_odd() {
1228+
return 0;
1229+
}
1230+
1231+
let digit_pairs = self.digits.to_radix_le(100);
1232+
let loc = digit_pairs.iter().position(|&d| d != 0).unwrap_or(0);
1233+
1234+
2 * loc + usize::from(digit_pairs[loc] % 10 == 0)
1235+
}
1236+
12241237
/// Split into components
12251238
pub(crate) fn as_parts(&self) -> (Sign, i64, &BigUint) {
12261239
(self.sign, self.scale, self.digits)

0 commit comments

Comments
 (0)