]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Add support routines to generate strings for fixed point
authorDavid Zafman <dzafman@redhat.com>
Fri, 9 Aug 2019 01:06:43 +0000 (18:06 -0700)
committerDavid Zafman <dzafman@redhat.com>
Fri, 18 Oct 2019 17:49:41 +0000 (10:49 -0700)
Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 8ac1562b4988fc3d52f92f15eb58075de0bcf27e)

Conflicts:
src/common/Formatter.h (trivial)

src/common/Formatter.cc
src/common/Formatter.h

index 2264c71171bc00a2ae6cecd74e8c3988ed77b142..6450859a599acafd28146852ad11181c14fb9865 100644 (file)
 // -----------------------
 namespace ceph {
 
+std::string
+fixed_u_to_string(uint64_t num, int scale)
+{
+       std::ostringstream t;
+
+       t.fill('0');
+       t.width(scale + 1);
+       t << num;
+       int len = t.str().size();
+       return t.str().substr(0,len - scale) + "." + t.str().substr(len - scale);
+}
+
+std::string
+fixed_to_string(int64_t num, int scale)
+{
+       std::ostringstream t;
+       bool neg = num < 0;
+       if (neg) num = -num;
+
+       t.fill('0');
+       t.width(scale + 1);
+       t << num;
+       int len = t.str().size();
+       return (neg ? "-" : "") + t.str().substr(0,len - scale) + "." + t.str().substr(len - scale);
+}
+
 /*
  * FormatterAttrs(const char *attr, ...)
  *
index 4a9ac3210e083104ff3538affbeb8c8f6cb1570b..3e9e1df9f65694d3c3f0bc4e767f3a2f6cb315e5 100644 (file)
@@ -254,6 +254,7 @@ namespace ceph {
     std::vector< std::string > m_column_name;
   };
 
-
+  std::string fixed_to_string(int64_t num, int scale);
+  std::string fixed_u_to_string(uint64_t num, int scale);
 }
 #endif