Fix formatting of zero bytes

Previously, that would raise a ValueError (math domain error), because
log(0) is undefined.
This commit is contained in:
Jonas Schäfer
2022-01-10 17:31:50 +01:00
parent aed9ad1cde
commit b4e6ee8943

View File

@@ -53,7 +53,10 @@ def circle_name(c: typing.Any) -> str:
def format_bytes(n: float) -> str:
scale = math.floor(math.log(n, 1024))
try:
scale = max(math.floor(math.log(n, 1024)), 0)
except ValueError:
scale = 0
try:
unit = BYTE_UNIT_SCALE_MAP[scale]
factor = 1024**scale