Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
16 changes: 15 additions & 1 deletion binary_reader/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down