diff --git a/README.md b/README.md index ecdd892..5e3c902 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ These are the types that can be used with BinaryReader. Just add `read_` or `wri uint8, int8, uint16, int16, half_float uint32, int32, float -uint64, int64, +uint64, int64, double bytes, str ``` diff --git a/binary_reader/binary_reader.py b/binary_reader/binary_reader.py index de05b11..e819a87 100644 --- a/binary_reader/binary_reader.py +++ b/binary_reader/binary_reader.py @@ -15,7 +15,7 @@ FMT[c] = 2 for c in ["i", "I", "f"]: FMT[c] = 4 -for c in ["q", "Q"]: +for c in ["q", "Q", "d"]: FMT[c] = 8 @@ -345,6 +345,14 @@ def read_uint8(self, count=None) -> Union[int, Tuple[int]]: return self.__read_type("B", count) return self.__read_type("B")[0] + def read_double(self, count=None) -> Union[float, Tuple[float]]: + """Reads a 64-bit float (double-precision).\n + If count is given, will return a tuple of values instead of 1 value. + """ + if count is not None: + return self.__read_type("d", count) + return self.__read_type("d")[0] + def read_float(self, count=None) -> Union[float, Tuple[float]]: """Reads a 32-bit float.\n If count is given, will return a tuple of values instead of 1 value. @@ -479,6 +487,12 @@ def write_uint8(self, value: int) -> None: """ self.__write_type("B", value, self.is_iterable(value)) + def write_double(self, value: float) -> None: + """Writes a 64-bit float (double-precision).\n + If value is iterable, will write all of the elements in the given iterable. + """ + self.__write_type("d", value, self.is_iterable(value)) + def write_float(self, value: float) -> None: """Writes a 32-bit float.\n If value is iterable, will write all of the elements in the given iterable.