From beaf9fb7e37acc3cee1c12eb6eeb8733a97d0689 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 20 Mar 2018 21:15:55 +0200 Subject: [PATCH] Use NumBits as generic param --- src/ttmath.nim | 22 +++++++++++----------- tests/test1.nim | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ttmath.nim b/src/ttmath.nim index f7cf3d9..47ad5cd 100644 --- a/src/ttmath.nim +++ b/src/ttmath.nim @@ -7,20 +7,20 @@ const ttmathPath = currentSourcePath.rsplit(DirSep, 1)[0] const TTMATH_HEADER = ttmathPath & DirSep & "headers" & DirSep & "ttmath.h" type - UInt* {.importcpp: "ttmath::UInt<'0 / sizeof(ttmath::uint)>", header: TTMATH_HEADER.} [NumBytes: static[int]] = object - table*: array[NumBytes div sizeof(uint), uint] # TODO: This should likely be private, but it's used in nimbus... + UInt* {.importcpp: "ttmath::UInt<'0 / 8 / sizeof(ttmath::uint)>", header: TTMATH_HEADER.} [NumBits: static[int]] = object + table*: array[NumBits div 8 div sizeof(uint), uint] # TODO: This should likely be private, but it's used in nimbus... - Int* {.importcpp: "ttmath::Int<'0 / sizeof(ttmath::uint)>", header: TTMATH_HEADER.} [NumBytes: static[int]] = object + Int* {.importcpp: "ttmath::Int<'0 / 8 / sizeof(ttmath::uint)>", header: TTMATH_HEADER.} [NumBits: static[int]] = object - Int256* = Int[32] - Int512* = Int[64] - Int1024* = Int[128] - Int2048* = Int[256] + Int256* = Int[256] + Int512* = Int[512] + Int1024* = Int[1024] + Int2048* = Int[2048] - UInt256* = UInt[32] - UInt512* = UInt[64] - UInt1024* = UInt[128] - UInt2048* = UInt[256] + UInt256* = UInt[256] + UInt512* = UInt[512] + UInt1024* = UInt[1024] + UInt2048* = UInt[2048] TTInt = Int or UInt diff --git a/tests/test1.nim b/tests/test1.nim index 64c8f56..2e17d2e 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -4,9 +4,11 @@ suite "ttmath": test "Ints": let a = i256"12345678910111213141516" let b = i256"16151413121110987654321" + check sizeof(a) == 32 check $(a + b) == "28497092031222200795837" test "UInts": let a = u256"12345678910111213141516" let b = u256"16151413121110987654321" + check sizeof(a) == 32 check $(a + b) == "28497092031222200795837"