@@ -266,19 +266,21 @@ impl ToStrRadix for $T {
266
266
impl Primitive for $T { }
267
267
268
268
impl Bitwise for $T {
269
- /// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic .
269
+ /// Returns the number of ones in the binary representation of the number .
270
270
#[ inline]
271
- fn population_count ( & self ) -> $T {
272
- ( * self as $T_SIGNED) . population_count ( ) as $T
271
+ fn count_ones ( & self ) -> $T {
272
+ ( * self as $T_SIGNED) . count_ones ( ) as $T
273
273
}
274
274
275
- /// Counts the number of leading zeros. Wraps LLVM's `ctlz` intrinsic.
275
+ /// Returns the number of leading zeros in the in the binary representation
276
+ /// of the number.
276
277
#[ inline]
277
278
fn leading_zeros( & self ) -> $T {
278
279
( * self as $T_SIGNED) . leading_zeros( ) as $T
279
280
}
280
281
281
- /// Counts the number of trailing zeros. Wraps LLVM's `cttz` intrinsic.
282
+ /// Returns the number of trailing zeros in the in the binary representation
283
+ /// of the number.
282
284
#[ inline]
283
285
fn trailing_zeros( & self ) -> $T {
284
286
( * self as $T_SIGNED) . trailing_zeros( ) as $T
@@ -375,8 +377,17 @@ mod tests {
375
377
}
376
378
377
379
#[ test]
378
- fn test_bitcount( ) {
379
- assert_eq!( ( 0b010101 as $T) . population_count( ) , 3 ) ;
380
+ fn test_count_ones( ) {
381
+ assert_eq!( ( 0b0101100 as $T) . count_ones( ) , 3 ) ;
382
+ assert_eq!( ( 0b0100001 as $T) . count_ones( ) , 2 ) ;
383
+ assert_eq!( ( 0b1111001 as $T) . count_ones( ) , 5 ) ;
384
+ }
385
+
386
+ #[ test]
387
+ fn test_count_zeros( ) {
388
+ assert_eq!( ( 0b0101100 as $T) . count_zeros( ) , BITS as $T - 3 ) ;
389
+ assert_eq!( ( 0b0100001 as $T) . count_zeros( ) , BITS as $T - 2 ) ;
390
+ assert_eq!( ( 0b1111001 as $T) . count_zeros( ) , BITS as $T - 5 ) ;
380
391
}
381
392
382
393
#[ test]
0 commit comments