add count_leading_zeros, count_trailing_zeros, and count_ones implementations
[vector-math.git] / src / prim.rs
index ea7b6b94010b7bf78da9a1873dd8b158340d1285..7ba23e5b394ba9fe9c9ea1f18a43ee9fbacd9a3b 100644 (file)
@@ -91,6 +91,7 @@ pub trait PrimInt:
     const ONE: Self;
     const MIN: Self;
     const MAX: Self;
+    const BITS: Self;
 }
 
 pub trait PrimUInt: PrimInt + ConvertFrom<Self::SignedType> {
@@ -110,12 +111,14 @@ macro_rules! impl_int {
             const ONE: Self = 1;
             const MIN: Self = 0;
             const MAX: Self = !0;
+            const BITS: Self = (0 as $uint).count_zeros() as $uint;
         }
         impl PrimInt for $sint {
             const ZERO: Self = 0;
             const ONE: Self = 1;
             const MIN: Self = $sint::MIN;
             const MAX: Self = $sint::MAX;
+            const BITS: Self = (0 as $sint).count_zeros() as $sint;
         }
         impl PrimUInt for $uint {
             type SignedType = $sint;