mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
JS: fix div uint64 no truncation (#16899)
This commit is contained in:
@@ -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
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()
|
||||
|
||||
Reference in New Issue
Block a user