From: Adrián Arroyo Calle Date: Fri, 20 Aug 2021 10:38:15 +0000 (+0200) Subject: Fix #1009 by providing a naive num-bigint implementation of count_ones X-Git-Tag: v0.9.0~46^2~1 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=3c5a94452a46a22990fb6e9c4b41a653d0e360ac;p=scryer-prolog.git Fix #1009 by providing a naive num-bigint implementation of count_ones --- diff --git a/crates/num-rug-adapter/src/lib.rs b/crates/num-rug-adapter/src/lib.rs index a95d42c8..2f67b80d 100644 --- a/crates/num-rug-adapter/src/lib.rs +++ b/crates/num-rug-adapter/src/lib.rs @@ -117,6 +117,10 @@ impl Integer { pub fn gcd(&self, other: &Self) -> Self { Integer(num_integer::Integer::gcd(&self.0, &other.0)) } + + pub fn count_ones(&self) -> Option { + Some(self.0.to_u32_digits().1.iter().map(|&d| d.count_ones()).sum()) + } } impl From<&Integer> for Integer {