Repository: HdrHistogram/HdrHistogram_py

Issue:
PayloadHeader conversion_ratio_bits type should be c_double
Based on the [Encoded Histogram format wiki](https://github.com/HdrHistogram/HdrHistogram.NET/wiki/Encoded-Histogram-format), the header element `Integer to double conversion ratio` is a double precision float. Currently the python version is using a long data type which alters the encoded output. 





Discussion:

Patch:
diff --git a/hdrh/codec.py b/hdrh/codec.py
index a3f38f8..e6f2e3b 100644
--- a/hdrh/codec.py
+++ b/hdrh/codec.py
@@ -35,6 +35,7 @@ from ctypes import c_byte
 from ctypes import c_ushort
 from ctypes import c_uint
 from ctypes import c_ulonglong
+from ctypes import c_double
 
 import zlib
 
@@ -98,7 +99,7 @@ class PayloadHeader(BigEndianStructure):
         ("significant_figures", c_uint),
         ("lowest_trackable_value", c_ulonglong),
         ("highest_trackable_value", c_ulonglong),
-        ("conversion_ratio_bits", c_ulonglong)]
+        ("conversion_ratio_bits", c_double)]
 
 
 payload_header_size = ctypes.sizeof(PayloadHeader)
diff --git a/hdrh/histogram.py b/hdrh/histogram.py
index 8eb4951..a17a0a6 100644
--- a/hdrh/histogram.py
+++ b/hdrh/histogram.py
@@ -574,6 +574,9 @@ class HdrHistogram():
     def get_word_size(self):
         return self.word_size
 
+    def get_int_to_double_conversion_ratio(self):
+        return self.int_to_double_conversion_ratio
+
     def output_percentile_distribution(self,
                                        out_file,
                                        output_value_unit_scaling_ratio,


Test patch:
diff --git a/test/test_hdrhistogram.py b/test/test_hdrhistogram.py
index 867d7a3..469e92f 100644
--- a/test/test_hdrhistogram.py
+++ b/test/test_hdrhistogram.py
@@ -425,17 +425,17 @@ def check_hist_encode(word_size,
 ENCODE_ARG_LIST = (
     # word size digits  expected_compressed_length, fill_start%, fill_count%
     # best case when all counters are zero
-    (8, 3, 48, 0, 0),        # V1=52 385 = size when compressing entire counts array
-    (8, 2, 48, 0, 0),        # 126
+    (8, 3, 52, 0, 0),        # V1=52 385 = size when compressing entire counts array
+    (8, 2, 52, 0, 0),        # 126
     # typical case when all counters are aggregated in a small contiguous area
-    (8, 3, 15560, 30, 20),   # V1=16452
-    (8, 2, 1688, 30, 20),    # V1=2096
+    (8, 3, 15564, 30, 20),   # V1=16452
+    (8, 2, 1692, 30, 20),    # V1=2096
     # worst case when all counters are different
     (8, 3, 76892, 0, 100),   # V1=80680
-    (8, 2, 9340, 0, 100),    # V1=10744
+    (8, 2, 9344, 0, 100),    # V1=10744
     # worst case 32-bit and 16-bit counters
     (2, 3, 76892, 0, 100),   # V1=68936
-    (2, 2, 9340, 0, 100),    # V1=9144
+    (2, 2, 9344, 0, 100),    # V1=9144
 )
 
 @pytest.mark.codec
@@ -618,6 +618,8 @@ def test_jHiccup_v2_log():
             accumulated_histogram.add(decoded_histogram)
             # These logs use 8 byte counters
             assert decoded_histogram.get_word_size() == 8
+            # These logs use the default 1.0 conversion ratio
+            assert decoded_histogram.get_int_to_double_conversion_ratio() == 1.0
         for statement in target_numbers:
             assert eval(statement) == target_numbers[statement]