types and casts
diff --git a/req/include/req_common.hpp b/req/include/req_common.hpp
index d2dc518..0e5b87a 100755
--- a/req/include/req_common.hpp
+++ b/req/include/req_common.hpp
@@ -29,7 +29,8 @@
 namespace datasketches {
 
 // TODO: have a common random bit with KLL
-static std::independent_bits_engine<std::mt19937, 1, unsigned> req_random_bit(std::chrono::system_clock::now().time_since_epoch().count());
+static std::independent_bits_engine<std::mt19937, 1, unsigned>
+  req_random_bit(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()));
 
 namespace req_constants {
   static const uint16_t MIN_K = 4;
diff --git a/req/include/req_compactor.hpp b/req/include/req_compactor.hpp
index 2ca768b..682aa49 100755
--- a/req/include/req_compactor.hpp
+++ b/req/include/req_compactor.hpp
@@ -110,8 +110,8 @@
 
   bool ensure_enough_sections();
   std::pair<uint32_t, uint32_t> compute_compaction_range(uint32_t secs_to_compact) const;
-  void grow(size_t new_capacity);
-  void ensure_space(size_t num);
+  void grow(uint32_t new_capacity);
+  void ensure_space(uint32_t num);
 
   static uint32_t nearest_even(float value);
 
@@ -123,10 +123,10 @@
   req_compactor(bool hra, uint8_t lg_weight, bool sorted, float section_size_raw, uint8_t num_sections, uint64_t state, std::unique_ptr<T, items_deleter> items, uint32_t num_items, const Allocator& allocator);
 
   template<typename S>
-  static std::unique_ptr<T, items_deleter> deserialize_items(std::istream& is, const S& serde, const Allocator& allocator, size_t num);
+  static std::unique_ptr<T, items_deleter> deserialize_items(std::istream& is, const S& serde, const Allocator& allocator, uint32_t num);
 
   template<typename S>
-  static std::pair<std::unique_ptr<T, items_deleter>, size_t> deserialize_items(const void* bytes, size_t size, const S& serde, const Allocator& allocator, size_t num);
+  static std::pair<std::unique_ptr<T, items_deleter>, size_t> deserialize_items(const void* bytes, size_t size, const S& serde, const Allocator& allocator, uint32_t num);
 
 };
 
diff --git a/req/include/req_compactor_impl.hpp b/req/include/req_compactor_impl.hpp
index ef0b8a6..ed078ac 100755
--- a/req/include/req_compactor_impl.hpp
+++ b/req/include/req_compactor_impl.hpp
@@ -172,7 +172,7 @@
 }
 
 template<typename T, typename C, typename A>
-void req_compactor<T, C, A>::grow(size_t new_capacity) {
+void req_compactor<T, C, A>::grow(uint32_t new_capacity) {
   T* new_items = allocator_.allocate(new_capacity);
   size_t new_i = hra_ ? new_capacity - num_items_ : 0;
   for (auto it = begin(); it != end(); ++it, ++new_i) {
@@ -185,7 +185,7 @@
 }
 
 template<typename T, typename C, typename A>
-void req_compactor<T, C, A>::ensure_space(size_t num) {
+void req_compactor<T, C, A>::ensure_space(uint32_t num) {
   if (num_items_ + num > capacity_) grow(num_items_ + num + get_nom_capacity());
 }
 
@@ -240,7 +240,7 @@
 std::pair<uint32_t, uint32_t> req_compactor<T, C, A>::compact(req_compactor& next) {
   const uint32_t starting_nom_capacity = get_nom_capacity();
   // choose a part of the buffer to compact
-  const uint32_t secs_to_compact = std::min<uint32_t>(count_trailing_zeros_in_u32(~state_) + 1, num_sections_);
+  const uint32_t secs_to_compact = std::min<uint32_t>(count_trailing_zeros_in_u64(~state_) + 1, num_sections_);
   auto compaction_range = compute_compaction_range(secs_to_compact);
   if (compaction_range.second - compaction_range.first < 2) throw std::logic_error("compaction range error");
 
@@ -267,7 +267,7 @@
 
 template<typename T, typename C, typename A>
 bool req_compactor<T, C, A>::ensure_enough_sections() {
-  const float ssr = section_size_raw_ / sqrt(2);
+  const float ssr = section_size_raw_ / sqrtf(2);
   const uint32_t ne = nearest_even(ssr);
   if (state_ >= static_cast<uint64_t>(1ULL << (num_sections_ - 1)) && ne >= req_constants::MIN_K) {
     section_size_raw_ = ssr;
@@ -284,8 +284,8 @@
   uint32_t non_compact = get_nom_capacity() / 2 + (num_sections_ - secs_to_compact) * section_size_;
   // make compacted region even
   if (((num_items_ - non_compact) & 1) == 1) ++non_compact;
-  const size_t low = hra_ ? 0 : non_compact;
-  const size_t high = hra_ ? num_items_ - non_compact : num_items_;
+  const uint32_t low = hra_ ? 0 : non_compact;
+  const uint32_t high = hra_ ? num_items_ - non_compact : num_items_;
   return std::pair<uint32_t, uint32_t>(low, high);
 }
 
@@ -381,7 +381,7 @@
 
 template<typename T, typename C, typename A>
 template<typename S>
-auto req_compactor<T, C, A>::deserialize_items(std::istream& is, const S& serde, const A& allocator, size_t num)
+auto req_compactor<T, C, A>::deserialize_items(std::istream& is, const S& serde, const A& allocator, uint32_t num)
 -> std::unique_ptr<T, items_deleter> {
   A alloc(allocator);
   std::unique_ptr<T, items_deleter> items(alloc.allocate(num), items_deleter(allocator, false, num));
@@ -430,7 +430,7 @@
 
 template<typename T, typename C, typename A>
 template<typename S>
-auto req_compactor<T, C, A>::deserialize_items(const void* bytes, size_t size, const S& serde, const A& allocator, size_t num)
+auto req_compactor<T, C, A>::deserialize_items(const void* bytes, size_t size, const S& serde, const A& allocator, uint32_t num)
 -> std::pair<std::unique_ptr<T, items_deleter>, size_t> {
   const char* ptr = static_cast<const char*>(bytes);
   const char* end_ptr = static_cast<const char*>(bytes) + size;
@@ -465,22 +465,22 @@
 template<typename T, typename C, typename A>
 class req_compactor<T, C, A>::items_deleter {
   public:
-  items_deleter(const A& allocator, bool destroy, uint32_t num): allocator(allocator), destroy(destroy), num(num) {}
+  items_deleter(const A& allocator, bool destroy, size_t num): allocator_(allocator), destroy_(destroy), num_(num) {}
   void operator() (T* ptr) {
     if (ptr != nullptr) {
-      if (destroy) {
-        for (uint32_t i = 0; i < num; ++i) {
+      if (destroy_) {
+        for (size_t i = 0; i < num_; ++i) {
           ptr[i].~T();
         }
       }
-      allocator.deallocate(ptr, num);
+      allocator_.deallocate(ptr, num_);
     }
   }
-  void set_destroy(bool destroy) { this->destroy = destroy; }
+  void set_destroy(bool destroy) { destroy_ = destroy; }
   private:
-  A allocator;
-  bool destroy;
-  uint32_t num;
+  A allocator_;
+  bool destroy_;
+  size_t num_;
 };
 
 } /* namespace datasketches */
diff --git a/req/test/req_sketch_test.cpp b/req/test/req_sketch_test.cpp
index 0be4aa5..a301a04 100755
--- a/req/test/req_sketch_test.cpp
+++ b/req/test/req_sketch_test.cpp
@@ -55,15 +55,15 @@
 
 TEST_CASE("req sketch: single value, lra", "[req_sketch]") {
   req_sketch<float> sketch(12, false);
-  sketch.update(1);
+  sketch.update(1.0f);
   REQUIRE_FALSE(sketch.is_HRA());
   REQUIRE_FALSE(sketch.is_empty());
   REQUIRE_FALSE(sketch.is_estimation_mode());
   REQUIRE(sketch.get_n() == 1);
   REQUIRE(sketch.get_num_retained() == 1);
-  REQUIRE(sketch.get_rank(1) == 0);
-  REQUIRE(sketch.get_rank<true>(1) == 1);
-  REQUIRE(sketch.get_rank(1.1) == 1);
+  REQUIRE(sketch.get_rank(1.0f) == 0);
+  REQUIRE(sketch.get_rank<true>(1.0f) == 1);
+  REQUIRE(sketch.get_rank(1.1f) == 1);
   REQUIRE(sketch.get_rank(std::numeric_limits<float>::infinity()) == 1);
   REQUIRE(sketch.get_quantile(0) == 1);
   REQUIRE(sketch.get_quantile(0.5) == 1);
@@ -86,43 +86,43 @@
 
 TEST_CASE("req sketch: repeated values", "[req_sketch]") {
   req_sketch<float> sketch(12);
-  sketch.update(1);
-  sketch.update(1);
-  sketch.update(1);
-  sketch.update(2);
-  sketch.update(2);
-  sketch.update(2);
+  sketch.update(1.0f);
+  sketch.update(1.0f);
+  sketch.update(1.0f);
+  sketch.update(2.0f);
+  sketch.update(2.0f);
+  sketch.update(2.0f);
   REQUIRE_FALSE(sketch.is_empty());
   REQUIRE_FALSE(sketch.is_estimation_mode());
   REQUIRE(sketch.get_n() == 6);
   REQUIRE(sketch.get_num_retained() == 6);
-  REQUIRE(sketch.get_rank(1) == 0);
-  REQUIRE(sketch.get_rank<true>(1) == 0.5);
-  REQUIRE(sketch.get_rank(2) == 0.5);
-  REQUIRE(sketch.get_rank<true>(2) == 1);
+  REQUIRE(sketch.get_rank(1.0f) == 0);
+  REQUIRE(sketch.get_rank<true>(1.0f) == 0.5);
+  REQUIRE(sketch.get_rank(2.0f) == 0.5);
+  REQUIRE(sketch.get_rank<true>(2.0f) == 1);
 }
 
 TEST_CASE("req sketch: exact mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
-  for (size_t i = 1; i <= 10; ++i) sketch.update(i);
+  for (size_t i = 1; i <= 10; ++i) sketch.update(static_cast<float>(i));
   REQUIRE_FALSE(sketch.is_empty());
   REQUIRE_FALSE(sketch.is_estimation_mode());
   REQUIRE(sketch.get_n() == 10);
   REQUIRE(sketch.get_num_retained() == 10);
 
   // like KLL
-  REQUIRE(sketch.get_rank(1) == 0);
-  REQUIRE(sketch.get_rank(2) == 0.1);
-  REQUIRE(sketch.get_rank(6) == 0.5);
-  REQUIRE(sketch.get_rank(9) == 0.8);
-  REQUIRE(sketch.get_rank(10) == 0.9);
+  REQUIRE(sketch.get_rank(1.0f) == 0);
+  REQUIRE(sketch.get_rank(2.0f) == 0.1);
+  REQUIRE(sketch.get_rank(6.0f) == 0.5);
+  REQUIRE(sketch.get_rank(9.0f) == 0.8);
+  REQUIRE(sketch.get_rank(10.0f) == 0.9);
 
   // inclusive
-  REQUIRE(sketch.get_rank<true>(1) == 0.1);
-  REQUIRE(sketch.get_rank<true>(2) == 0.2);
-  REQUIRE(sketch.get_rank<true>(5) == 0.5);
-  REQUIRE(sketch.get_rank<true>(9) == 0.9);
-  REQUIRE(sketch.get_rank<true>(10) == 1);
+  REQUIRE(sketch.get_rank<true>(1.0f) == 0.1);
+  REQUIRE(sketch.get_rank<true>(2.0f) == 0.2);
+  REQUIRE(sketch.get_rank<true>(5.0f) == 0.5);
+  REQUIRE(sketch.get_rank<true>(9.0f) == 0.9);
+  REQUIRE(sketch.get_rank<true>(10.0f) == 1);
 
   // like KLL
   REQUIRE(sketch.get_quantile(0) == 1);
@@ -164,16 +164,16 @@
 TEST_CASE("req sketch: estimation mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 100000;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE_FALSE(sketch.is_empty());
   REQUIRE(sketch.is_estimation_mode());
   REQUIRE(sketch.get_n() == n);
 //  std::cout << sketch.to_string(true);
   REQUIRE(sketch.get_num_retained() < n);
   REQUIRE(sketch.get_rank(0) == 0);
-  REQUIRE(sketch.get_rank(n) == 1);
-  REQUIRE(sketch.get_rank(n / 2) == Approx(0.5).margin(0.01));
-  REQUIRE(sketch.get_rank(n - 1) == Approx(1).margin(0.01));
+  REQUIRE(sketch.get_rank(static_cast<float>(n)) == 1);
+  REQUIRE(sketch.get_rank(n / 2.0f) == Approx(0.5).margin(0.01));
+  REQUIRE(sketch.get_rank(n - 1.0f) == Approx(1).margin(0.01));
   REQUIRE(sketch.get_min_value() == 0);
   REQUIRE(sketch.get_max_value() == n - 1);
   REQUIRE(sketch.get_rank_lower_bound(0.5, 1) < 0.5);
@@ -219,7 +219,7 @@
 
 TEST_CASE("req sketch: stream serialize-deserialize single item", "[req_sketch]") {
   req_sketch<float> sketch(12);
-  sketch.update(1);
+  sketch.update(1.0f);
 
   std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
   sketch.serialize(s);
@@ -235,7 +235,7 @@
 
 TEST_CASE("req sketch: byte serialize-deserialize single item", "[req_sketch]") {
   req_sketch<float> sketch(12);
-  sketch.update(1);
+  sketch.update(1.0f);
 
   auto bytes = sketch.serialize();
   REQUIRE(bytes.size() == sketch.get_serialized_size_bytes());
@@ -253,7 +253,7 @@
 TEST_CASE("req sketch: stream serialize-deserialize exact mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 50;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE_FALSE(sketch.is_estimation_mode());
 
   std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
@@ -271,7 +271,7 @@
 TEST_CASE("req sketch: byte serialize-deserialize exact mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 50;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE_FALSE(sketch.is_estimation_mode());
 
   auto bytes = sketch.serialize();
@@ -290,7 +290,7 @@
 TEST_CASE("req sketch: stream serialize-deserialize estimation mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 100000;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE(sketch.is_estimation_mode());
 
   std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
@@ -308,7 +308,7 @@
 TEST_CASE("req sketch: byte serialize-deserialize estimation mode", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 100000;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE(sketch.is_estimation_mode());
 
   auto bytes = sketch.serialize();
@@ -326,7 +326,7 @@
 TEST_CASE("req sketch: serialize deserialize stream and bytes equivalence", "[req_sketch]") {
   req_sketch<float> sketch(12);
   const size_t n = 100000;
-  for (size_t i = 0; i < n; ++i) sketch.update(i);
+  for (size_t i = 0; i < n; ++i) sketch.update(static_cast<float>(i));
   REQUIRE(sketch.is_estimation_mode());
 
   std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
@@ -373,8 +373,8 @@
   REQUIRE(sketch.get_num_retained() == 1);
   REQUIRE(sketch.get_min_value() == 1);
   REQUIRE(sketch.get_max_value() == 1);
-  REQUIRE(sketch.get_rank(1) == 0);
-  REQUIRE(sketch.get_rank<true>(1) == 1);
+  REQUIRE(sketch.get_rank(1.0f) == 0);
+  REQUIRE(sketch.get_rank<true>(1.0f) == 1);
 }
 
 TEST_CASE("req sketch: stream deserialize from Java - raw items", "[req_sketch]") {
@@ -388,7 +388,7 @@
   REQUIRE(sketch.get_num_retained() == 4);
   REQUIRE(sketch.get_min_value() == 0);
   REQUIRE(sketch.get_max_value() == 3);
-  REQUIRE(sketch.get_rank(2) == 0.5);
+  REQUIRE(sketch.get_rank(2.0f) == 0.5);
 }
 
 TEST_CASE("req sketch: stream deserialize from Java - exact mode", "[req_sketch]") {
@@ -402,7 +402,7 @@
   REQUIRE(sketch.get_num_retained() == 100);
   REQUIRE(sketch.get_min_value() == 0);
   REQUIRE(sketch.get_max_value() == 99);
-  REQUIRE(sketch.get_rank(50) == 0.5);
+  REQUIRE(sketch.get_rank(50.0f) == 0.5);
 }
 
 TEST_CASE("req sketch: stream deserialize from Java - estimation mode", "[req_sketch]") {
@@ -416,14 +416,14 @@
   REQUIRE(sketch.get_num_retained() == 2942);
   REQUIRE(sketch.get_min_value() == 0);
   REQUIRE(sketch.get_max_value() == 9999);
-  REQUIRE(sketch.get_rank(5000) == 0.5);
+  REQUIRE(sketch.get_rank(5000.0f) == 0.5);
 }
 
 TEST_CASE("req sketch: merge into empty", "[req_sketch]") {
   req_sketch<float> sketch1(40);
 
   req_sketch<float> sketch2(40);
-  for (size_t i = 0; i < 1000; ++i) sketch2.update(i);
+  for (size_t i = 0; i < 1000; ++i) sketch2.update(static_cast<float>(i));
 
   sketch1.merge(sketch2);
   REQUIRE(sketch1.get_min_value() == 0);
@@ -431,15 +431,15 @@
   REQUIRE(sketch1.get_quantile(0.25) == Approx(250).margin(3));
   REQUIRE(sketch1.get_quantile(0.5) == Approx(500).margin(3));
   REQUIRE(sketch1.get_quantile(0.75) == Approx(750).margin(3));
-  REQUIRE(sketch1.get_rank(500) == Approx(0.5).margin(0.01));
+  REQUIRE(sketch1.get_rank(500.0f) == Approx(0.5).margin(0.01));
 }
 
 TEST_CASE("req sketch: merge", "[req_sketch]") {
   req_sketch<float> sketch1(100);
-  for (size_t i = 0; i < 1000; ++i) sketch1.update(i);
+  for (size_t i = 0; i < 1000; ++i) sketch1.update(static_cast<float>(i));
 
   req_sketch<float> sketch2(100);
-  for (size_t i = 1000; i < 2000; ++i) sketch2.update(i);
+  for (size_t i = 1000; i < 2000; ++i) sketch2.update(static_cast<float>(i));
 
   sketch1.merge(sketch2);
   REQUIRE(sketch1.get_min_value() == 0);
@@ -447,18 +447,18 @@
   REQUIRE(sketch1.get_quantile(0.25) == Approx(500).margin(3));
   REQUIRE(sketch1.get_quantile(0.5) == Approx(1000).margin(1));
   REQUIRE(sketch1.get_quantile(0.75) == Approx(1500).margin(1));
-  REQUIRE(sketch1.get_rank(1000) == Approx(0.5).margin(0.01));
+  REQUIRE(sketch1.get_rank(1000.0f) == Approx(0.5).margin(0.01));
 }
 
 TEST_CASE("req sketch: merge multiple", "[req_sketch]") {
   req_sketch<float> sketch1(12);
-  for (size_t i = 0; i < 40; ++i) sketch1.update(i);
+  for (size_t i = 0; i < 40; ++i) sketch1.update(static_cast<float>(i));
 
   req_sketch<float> sketch2(12);
-  for (size_t i = 40; i < 80; ++i) sketch2.update(i);
+  for (size_t i = 40; i < 80; ++i) sketch2.update(static_cast<float>(i));
 
   req_sketch<float> sketch3(12);
-  for (size_t i = 80; i < 120; ++i) sketch3.update(i);
+  for (size_t i = 80; i < 120; ++i) sketch3.update(static_cast<float>(i));
 
   req_sketch<float> sketch(12);
   sketch.merge(sketch1);
@@ -467,15 +467,15 @@
   REQUIRE(sketch.get_min_value() == 0);
   REQUIRE(sketch.get_max_value() == 119);
   REQUIRE(sketch.get_quantile(0.5) == Approx(60).margin(3));
-  REQUIRE(sketch.get_rank(60) == Approx(0.5).margin(0.01));
+  REQUIRE(sketch.get_rank(60.0f) == Approx(0.5).margin(0.01));
 }
 
 TEST_CASE("req sketch: merge incompatible HRA and LRA", "[req_sketch]") {
   req_sketch<float> sketch1(12);
-  sketch1.update(1);
+  sketch1.update(1.0f);
 
   req_sketch<float> sketch2(12, false);
-  sketch2.update(1);
+  sketch2.update(1.0f);
 
   REQUIRE_THROWS_AS(sketch1.merge(sketch2), std::invalid_argument);
 }