fixes operator precedence issue with nim 19.6

This commit is contained in:
andri lim 2019-10-22 18:07:35 +07:00 committed by zah
parent 5b9e73e488
commit c456190980
3 changed files with 37 additions and 11 deletions

View File

@ -13,31 +13,31 @@ template chkLT(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stint[bits], a) < fromHex(Stint[bits], b)
template chknotLT(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stint[bits], b) < fromHex(Stint[bits], a))
chk (not(fromHex(Stint[bits], b) < fromHex(Stint[bits], a)))
template chkLTE(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stint[bits], a) <= fromHex(Stint[bits], b)
template chknotLTE(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stint[bits], b) <= fromHex(Stint[bits], a))
chk (not(fromHex(Stint[bits], b) <= fromHex(Stint[bits], a)))
template chkEQ(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stint[bits], a) == fromHex(Stint[bits], b)
template chknotEQ(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stint[bits], a) == fromHex(Stint[bits], b))
chk (not(fromHex(Stint[bits], a) == fromHex(Stint[bits], b)))
template chkisZero(chk: untyped, a: string, bits: int) =
chk fromHex(Stint[bits], a).isZero()
template chknotisZero(chk: untyped, a: string, bits: int) =
chk not fromHex(Stint[bits], a).isZero()
chk (not fromHex(Stint[bits], a).isZero())
template chkisNegative(chk: untyped, a: string, bits: int) =
chk fromHex(Stint[bits], a).isNegative()
template chknotisNegative(chk: untyped, a: string, bits: int) =
chk not fromHex(Stint[bits], a).isNegative()
chk (not fromHex(Stint[bits], a).isNegative())
template chkisOdd(chk: untyped, a: string, bits: int) =
chk fromHex(Stint[bits], a).isOdd()
@ -49,7 +49,7 @@ template chkisEven(chk: untyped, a: string, bits: int) =
chk fromHex(Stint[bits], a).isEven()
template chknotisEven(chk: untyped, a: string, bits: int) =
chk not fromHex(Stint[bits], a).isEven()
chk (not fromHex(Stint[bits], a).isEven())
template ctTest(name: string, body: untyped) =
body

View File

@ -13,25 +13,25 @@ template chkLT(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stuint[bits], a) < fromHex(Stuint[bits], b)
template chknotLT(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stuint[bits], b) < fromHex(Stuint[bits], a))
chk (not(fromHex(Stuint[bits], b) < fromHex(Stuint[bits], a)))
template chkLTE(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stuint[bits], a) <= fromHex(Stuint[bits], b)
template chknotLTE(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stuint[bits], b) <= fromHex(Stuint[bits], a))
chk (not(fromHex(Stuint[bits], b) <= fromHex(Stuint[bits], a)))
template chkEQ(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b)
template chknotEQ(chk: untyped, a, b: string, bits: int) =
chk not(fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b))
chk (not(fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b)))
template chkisZero(chk: untyped, a: string, bits: int) =
chk fromHex(Stuint[bits], a).isZero()
template chknotisZero(chk: untyped, a: string, bits: int) =
chk not fromHex(Stuint[bits], a).isZero()
chk (not fromHex(Stuint[bits], a).isZero())
template chkisOdd(chk: untyped, a: string, bits: int) =
chk fromHex(Stuint[bits], a).isOdd()
@ -43,7 +43,7 @@ template chkisEven(chk: untyped, a: string, bits: int) =
chk fromHex(Stuint[bits], a).isEven()
template chknotisEven(chk: untyped, a: string, bits: int) =
chk not fromHex(Stuint[bits], a).isEven()
chk (not fromHex(Stuint[bits], a).isEven())
template ctTest(name: string, body: untyped) =
body

View File

@ -9,6 +9,32 @@
import ../stint, unittest
template chkMul(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stuint[bits], a) * fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c)
template chkDiv(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stuint[bits], a) div fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c)
template chkMod(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stuint[bits], a) mod fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c)
template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) =
chk (fromHex(Stuint[bits], a) divmod fromHex(Stuint[bits], b)) == (fromHex(Stuint[bits], c), fromHex(Stuint[bits], d))
template testMuldiv(chk, tst: untyped) =
tst "operator `mul`":
chkMul(chk, "0", "3", "0", 8)
#tst "operator `div`":
#tst "operator `mod`":
#tst "operator `divmod`":
static:
testMuldiv(doAssert, ctTest)
suite "Wider unsigned int muldiv coverage":
testMuldiv(check, test)
suite "Testing unsigned int multiplication implementation":
test "Multiplication with result fitting in low half":