Use NumBits as generic param

This commit is contained in:
Yuriy Glukhov 2018-03-20 21:15:55 +02:00 committed by zah
parent 462f2ae5ce
commit beaf9fb7e3
2 changed files with 13 additions and 11 deletions

View File

@ -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

View File

@ -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"