mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
implementation of Py310 int.bit_count
This commit is contained in:
1 parent
6bcd1da76b
commit
a21c6fb8ee
1 file changed
+12
@@ -653,6 +653,18 @@ impl PyInt {
|
||||
fn denominator(&self) -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
/// Returns the number of ones 1 an int. When the number is < 0,
|
||||
/// then it returns the number of ones of the absolute value.
|
||||
fn bit_count(&self) -> u32 {
|
||||
self.value
|
||||
.to_u32_digits()
|
||||
.1
|
||||
.iter()
|
||||
.map(|n| n.count_ones())
|
||||
.sum()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
|
||||
Reference in new issue
Block a user