You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2023/01/09 21:42:45 UTC

[datasketches-cpp] branch master updated: Explicitly cast constant uint64_ts that lose precision.

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new a7f78eb  Explicitly cast constant uint64_ts that lose precision.
     new 9a0c470  Merge pull request #327 from jbapple/implicit-double-cast
a7f78eb is described below

commit a7f78ebb954f363f98e514ec2636dc0caf54ff27
Author: Jim Apple <jb...@example.com>
AuthorDate: Mon Jan 9 11:10:44 2023 -0800

    Explicitly cast constant uint64_ts that lose precision.
    
    In clang-16, there are warnings like this upon build:
    
        warning: implicit conversion from 'const uint64_t' (aka 'const
        unsigned long') to 'double' changes value from 9223372036854775807
        to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
    
    Explicit casting fixes those warnings.
---
 theta/include/theta_helpers.hpp     | 2 +-
 theta/include/theta_sketch_impl.hpp | 3 ++-
 tuple/include/tuple_sketch_impl.hpp | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/theta/include/theta_helpers.hpp b/theta/include/theta_helpers.hpp
index 76c1c23..c74b226 100644
--- a/theta/include/theta_helpers.hpp
+++ b/theta/include/theta_helpers.hpp
@@ -55,7 +55,7 @@ public:
   // consistent way of initializing theta from p
   // avoids multiplication if p == 1 since it might not yield MAX_THETA exactly
   static uint64_t starting_theta_from_p(float p) {
-    if (p < 1) return static_cast<uint64_t>(theta_constants::MAX_THETA * p);
+    if (p < 1) return static_cast<float>(theta_constants::MAX_THETA) * p;
     return theta_constants::MAX_THETA;
   }
 
diff --git a/theta/include/theta_sketch_impl.hpp b/theta/include/theta_sketch_impl.hpp
index 2e06b89..28dc682 100644
--- a/theta/include/theta_sketch_impl.hpp
+++ b/theta/include/theta_sketch_impl.hpp
@@ -38,7 +38,8 @@ bool base_theta_sketch_alloc<A>::is_estimation_mode() const {
 
 template<typename A>
 double base_theta_sketch_alloc<A>::get_theta() const {
-  return static_cast<double>(get_theta64()) / theta_constants::MAX_THETA;
+  return static_cast<double>(get_theta64()) /
+         static_cast<double>(theta_constants::MAX_THETA);
 }
 
 template<typename A>
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index 74d601a..0766e4d 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -32,7 +32,8 @@ bool tuple_sketch<S, A>::is_estimation_mode() const {
 
 template<typename S, typename A>
 double tuple_sketch<S, A>::get_theta() const {
-  return static_cast<double>(get_theta64()) / theta_constants::MAX_THETA;
+  return static_cast<double>(get_theta64()) /
+         static_cast<double>(theta_constants::MAX_THETA);
 }
 
 template<typename S, typename A>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org