Skip to content
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
9 changes: 7 additions & 2 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import
ast, trees, magicsys, options,
nversion, msgs, idents, types,
ropes, ccgutils, wordrecg, renderer,
cgmeth, lowerings, sighashes, modulegraphs, lineinfos, rodutils,
cgmeth, lowerings, sighashes, modulegraphs, lineinfos,
transf, injectdestructors, sourcemap, astmsgs, backendpragmas

import pipelineutils
Expand All @@ -43,6 +43,7 @@ import strutils except addf
when defined(nimPreviewSlimSystem):
import std/[assertions, syncio]

import std/formatfloat

type
TJSGen = object of PPassContext
Expand Down Expand Up @@ -2900,7 +2901,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(abstractVarRange).kind == tyFloat32:
r.res.addFloatRoundtrip(f.float32)
else:
r.res.addFloatRoundtrip(f)
r.kind = resExpr
of nkCallKinds:
if isEmptyType(n.typ):
Expand Down
5 changes: 2 additions & 3 deletions tests/float/tfloats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ template main =
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()