use crate::natural::InnerNatural::{Large, Small};
use crate::natural::{Natural, limb_to_bit_count};
use crate::platform::Limb;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::TrailingZeros;
use malachite_base::slices::slice_leading_zeros;
pub_crate_test! {limbs_trailing_zeros(xs: &[Limb]) -> u64 {
let zeros = slice_leading_zeros(xs);
let remaining_zeros = TrailingZeros::trailing_zeros(xs[zeros]);
limb_to_bit_count(zeros)+ remaining_zeros
}}
impl Natural {
pub fn trailing_zeros(&self) -> Option<u64> {
match self {
&Self::ZERO => None,
Self(Small(small)) => Some(TrailingZeros::trailing_zeros(*small)),
Self(Large(limbs)) => Some(limbs_trailing_zeros(limbs)),
}
}
}