JS: fix div uint64 no truncation (#16899)

This commit is contained in:
flywind 2021-02-15 07:22:46 -06:00 • committed by GitHub
commit 339ebe958d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -671,7 +671,10 @@ proc arith(p: PProc, n: PNode, r: var TCompRes, op: TMagic) =
of mAddU: binaryUintExpr(p, n, r, "+")
of mSubU: binaryUintExpr(p, n, r, "-")
of mMulU: binaryUintExpr(p, n, r, "*")
of mDivU: binaryUintExpr(p, n, r, "/")
of mDivU:
binaryUintExpr(p, n, r, "/")
if n[1].typ.skipTypes(abstractRange).size == 8:
r.res = "Math.trunc($1)" % [r.res]
of mDivI:
arithAux(p, n, r, op)
of mModI:

19
tests/arithm/tdiv.nim Normal file
View file

@ -0,0 +1,19 @@
discard """
targets: "c js"
"""
block divUint64:
proc divTest() =
let x1 = 12'u16
let y = x1 div 5'u16
let x2 = 1345567'u32
let z = x2 div 5'u32
let a = 1345567'u64 div uint64(x1)
doAssert y == 2
doAssert z == 269113
doAssert a == 112130
static: divTest()
divTest()