We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6bcd1da commit a21c6fbCopy full SHA for a21c6fb
vm/src/obj/objint.rs
@@ -653,6 +653,18 @@ impl PyInt {
653
fn denominator(&self) -> usize {
654
1
655
}
656
+
657
+ #[pymethod]
658
+ /// Returns the number of ones 1 an int. When the number is < 0,
659
+ /// then it returns the number of ones of the absolute value.
660
+ fn bit_count(&self) -> u32 {
661
+ self.value
662
+ .to_u32_digits()
663
+ .1
664
+ .iter()
665
+ .map(|n| n.count_ones())
666
+ .sum()
667
+ }
668
669
670
#[derive(FromArgs)]
0 commit comments