aboutsummaryrefslogtreecommitdiff
path: root/src/integers.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/integers.nim')
-rw-r--r--src/integers.nim7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/integers.nim b/src/integers.nim
index 1b9121c..1f83488 100644
--- a/src/integers.nim
+++ b/src/integers.nim
@@ -22,3 +22,10 @@ proc `/^`*[T: Natural](x, y: T): T =
22 22
23proc truncateToUint8*(x: SomeUnsignedInt): uint8 = 23proc truncateToUint8*(x: SomeUnsignedInt): uint8 =
24 (x and wordBitMask).uint8 24 (x and wordBitMask).uint8
25
26iterator chunks*(totalBitLength: int, chunkType: typedesc[SomeInteger]): tuple[index: int, chunkBitLength: int] =
27 let chunkBitLength = sizeof(chunkType) * wordBitLength
28 let wordCount = totalBitLength div chunkBitLength
29 for i in 0..<(wordCount): yield (i, chunkBitLength)
30 let remainder = totalBitLength mod chunkBitLength
31 if remainder > 0: yield (wordCount, remainder)