Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsgen: fix incorrect float32-literal behaviour #824

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions compiler/backend/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Check `mapType` for the details.
"""

import
system/[
formatfloat
],
std/[
sets,
math,
Expand Down Expand Up @@ -50,9 +53,6 @@ import
nversion,
ropes
],
compiler/sem/[
rodutils,
],
compiler/backend/[
ccgutils,
]
Expand Down Expand Up @@ -2449,7 +2449,11 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
r.res = rope"Infinity"
of fcNegInf:
r.res = rope"-Infinity"
else: r.res = rope(f.toStrMaxPrecision)
else:
if n.typ.skipTypes(abstractRange).kind == tyFloat32:
r.res.addFloatRoundtrip(f.float32)
else:
r.res.addFloatRoundtrip(f)
r.kind = resExpr
of nkCall:
if isEmptyType(n.typ):
Expand Down
8 changes: 2 additions & 6 deletions tests/lang_types/float/tfloats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ template main =
doAssert $x2 == "1.32"
block:
var x = 1.23456789012345'f32
when nimvm:
discard # xxx, refs #12884
else:
when not defined(js):
doAssert x == 1.2345679'f32
doAssert $x == "1.2345679"
doAssert x == 1.2345679'f32
doAssert $x == "1.2345679"

static: main()
main()