mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
Merge pull request #2033 from reactormonk/round-in-js
Fixes #1959, rounding floats in JS
This commit is contained in:
@@ -1448,9 +1448,18 @@ proc genConv(p: PProc, n: PNode, r: var TCompRes) =
|
||||
var dest = skipTypes(n.typ, abstractVarRange)
|
||||
var src = skipTypes(n.sons[1].typ, abstractVarRange)
|
||||
gen(p, n.sons[1], r)
|
||||
if (dest.kind != src.kind) and (src.kind == tyBool):
|
||||
if dest.kind == src.kind:
|
||||
# no-op conversion
|
||||
return
|
||||
case dest.kind:
|
||||
of tyBool:
|
||||
r.res = ropef("(($1)? 1:0)" | "toBool($#)", [r.res])
|
||||
r.kind = resExpr
|
||||
of tyInt:
|
||||
r.res = ropef("($1|0)", [r.res])
|
||||
else:
|
||||
# TODO: What types must we handle here?
|
||||
discard
|
||||
|
||||
proc upConv(p: PProc, n: PNode, r: var TCompRes) =
|
||||
gen(p, n.sons[0], r) # XXX
|
||||
|
||||
7
tests/js/tfloatround.nim
Normal file
7
tests/js/tfloatround.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
discard """
|
||||
output: '''
|
||||
3
|
||||
'''
|
||||
"""
|
||||
|
||||
echo int(22 / 7)
|
||||
Reference in New Issue
Block a user