fixes 32bit problem

This commit is contained in:
andri lim 2019-10-25 16:25:31 +07:00 committed by zah
parent 7fe4db62dc
commit 2b5d083dac
2 changed files with 12 additions and 1 deletions

View File

@ -48,7 +48,7 @@ func extPrecAddMul[T: uint8 or uint16 or uint32](result: var UintImpl[T], x, y:
template extPrecMulImpl(result: var UintImpl[uint64], op: untyped, u, v: uint64) =
const
p = 64 div 2
base: uint64 = 1 shl p
base: uint64 = 1'u64 shl p
var
x0, x1, x2, x3: uint64

View File

@ -18,6 +18,9 @@ template chkDiv(chk: untyped, a, b, c: string, bits: int) =
template chkMod(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stint[bits], a) mod fromHex(Stint[bits], b)) == fromHex(Stint[bits], c)
template chkMod(chk: untyped, a, b, c: int, bits: int) =
chk (stint(a, bits) mod stint(b, bits)) == stint(c, bits)
template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) =
chk divmod(fromHex(Stint[bits], a), fromHex(Stint[bits], b)) == (fromHex(Stint[bits], c), fromHex(Stint[bits], d))
@ -204,6 +207,13 @@ template testMuldiv(chk, tst: untyped) =
chkDivMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1", "0", 128)
chkDivMod(chk, "0F", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD", "3", 128)
tst "issues with Nim v1.0.2":
block:
let x = -2.stint(256)
let y = 3200566678774828.stint(256)
let z = -6401133357549656.stint(256)
chk x * y == z
static:
testMuldiv(ctCheck, ctTest)
@ -320,3 +330,4 @@ suite "Testing signed int division and modulo implementation":
check: q == 123456789123456789'i64
check: r == 0'i64