JS: fix div uint64 no truncation (#16899)
This commit is contained in:
parent
55722fe04d
commit
339ebe958d
2 changed files with 23 additions and 1 deletions
|
|
@ -671,7 +671,10 @@ proc arith(p: PProc, n: PNode, r: var TCompRes, op: TMagic) =
|
||||||
of mAddU: binaryUintExpr(p, n, r, "+")
|
of mAddU: binaryUintExpr(p, n, r, "+")
|
||||||
of mSubU: binaryUintExpr(p, n, r, "-")
|
of mSubU: binaryUintExpr(p, n, r, "-")
|
||||||
of mMulU: 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:
|
of mDivI:
|
||||||
arithAux(p, n, r, op)
|
arithAux(p, n, r, op)
|
||||||
of mModI:
|
of mModI:
|
||||||
|
|
|
||||||
19
tests/arithm/tdiv.nim
Normal file
19
tests/arithm/tdiv.nim
Normal 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()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue