From af1274bfe7336f55b7c6a76b2e69f210f258c2a6 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Sat, 6 Jan 2024 02:11:24 +0000 Subject: [PATCH] Fix piece selection algorithm in docs (#524) --- book/src/bittorrent/piece-length.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/bittorrent/piece-length.md b/book/src/bittorrent/piece-length.md index 620cdacb..522907ac 100644 --- a/book/src/bittorrent/piece-length.md +++ b/book/src/bittorrent/piece-length.md @@ -58,7 +58,7 @@ MIN = 16 * 1024 MAX = 16 * 1024 * 1024 def piece_length(content_length): - exponent = math.log2(content_length) + exponent = math.ceil(math.log2(content_length)) length = 1 << int((exponent / 2 + 4)) return min(max(length, MIN), MAX) ```