]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
use llrintl when converting double to micro 2182/head
authorSage Weil <sage@redhat.com>
Thu, 31 Jul 2014 22:39:40 +0000 (15:39 -0700)
committerSage Weil <sage@redhat.com>
Thu, 31 Jul 2014 22:39:40 +0000 (15:39 -0700)
This avoids rounding error (noticeable on i386).

Backport: firefly
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/OSDMonitor.cc
src/osd/HitSet.h

index a8c2c64c6b45b1cf8f3fdde2c2bfc6e20fd70639..0cec4101e4afd8e509a6f6766a74c6f124f16bf9 100644 (file)
@@ -3481,6 +3481,7 @@ int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
   string interr, floaterr;
   int64_t n = 0;
   double f = 0;
+  int64_t uf = 0;  // micro-f
   if (!cmd_getval(g_ceph_context, cmdmap, "val", val)) {
     // wasn't a string; maybe an older mon forwarded json with an int?
     if (!cmd_getval(g_ceph_context, cmdmap, "val", n))
@@ -3490,6 +3491,7 @@ int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
     n = strict_strtoll(val.c_str(), 10, &interr);
     // or a float
     f = strict_strtod(val.c_str(), &floaterr);
+    uf = llrintl(f * (double)1000000.0);
   }
 
   if (!p.is_tier() &&
@@ -3684,7 +3686,7 @@ int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
       ss << "value must be in the range 0..1";
       return -ERANGE;
     }
-    p.cache_target_dirty_ratio_micro = f * (double)1000000.0;
+    p.cache_target_dirty_ratio_micro = uf;
   } else if (var == "cache_target_full_ratio") {
     if (floaterr.length()) {
       ss << "error parsing float '" << val << "': " << floaterr;
@@ -3694,7 +3696,7 @@ int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
       ss << "value must be in the range 0..1";
       return -ERANGE;
     }
-    p.cache_target_full_ratio_micro = f * (double)1000000.0;
+    p.cache_target_full_ratio_micro = uf;
   } else if (var == "cache_min_flush_age") {
     if (interr.length()) {
       ss << "error parsing int '" << val << "': " << interr;
index dd83e6dd8e5ef4c98fe8cd41b8e48e794f467894..b1f49c09cb13f15164021d55ce026be7b16c3fbf 100644 (file)
@@ -369,7 +369,7 @@ public:
       return (double)fpp_micro / 1000000.0;
     }
     void set_fpp(double f) {
-      fpp_micro = (unsigned)(f * 1000000.0);
+      fpp_micro = (unsigned)(llrintl(f * (double)1000000.0));
     }
 
     void encode(bufferlist& bl) const {