diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-04-27 08:33:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-27 17:33:03 +0200 |
commit | bb982c644b8e3e8a59cf2c60b28ff91741c7dc9b (patch) | |
tree | a922e3a355509a5d12fe7848a1e6c9f5ba3b2386 /compiler/jsgen.nim | |
parent | 664cb2c0be4e31d40cd3a5a2b9013f1afe47df97 (diff) | |
download | Nim-bb982c644b8e3e8a59cf2c60b28ff91741c7dc9b.tar.gz |
`$(a: float)` now works consistently in nim js, avoiding printing floats as ints (#14134)
* fix https://github.com/timotheecour/Nim/issues/133; $(a: float) works in nim js like in other backends * fix tests * fix test for windows that prints 1.1e17 differently than other OS
Diffstat (limited to 'compiler/jsgen.nim')
-rw-r--r-- | compiler/jsgen.nim | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 2461443cd..0e9575e9c 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -530,11 +530,10 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) = gen(p, n[1], r) xLoc = r.rdLoc - template applyFormat(frmtA, frmtB: string) = - if i == 0: - r.res = frmtA % [xLoc, yLoc] - else: - r.res = frmtB % [xLoc, yLoc] + template applyFormat(frmt) = + r.res = frmt % [xLoc, yLoc] + template applyFormat(frmtA, frmtB) = + if i == 0: applyFormat(frmtA) else: applyFormat(frmtB) case op: of mAddI: applyFormat("addInt($1, $2)", "($1 + $2)") @@ -596,7 +595,9 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) = of mBoolToStr: applyFormat("nimBoolToStr($1)", "nimBoolToStr($1)") of mIntToStr: applyFormat("cstrToNimstr(($1)+\"\")", "cstrToNimstr(($1)+\"\")") of mInt64ToStr: applyFormat("cstrToNimstr(($1)+\"\")", "cstrToNimstr(($1)+\"\")") - of mFloatToStr: applyFormat("cstrToNimstr(($1)+\"\")", "cstrToNimstr(($1)+\"\")") + of mFloatToStr: + useMagic(p, "nimFloatToString") + applyFormat "cstrToNimstr(nimFloatToString($1))" of mCStrToStr: applyFormat("cstrToNimstr($1)", "cstrToNimstr($1)") of mStrToStr, mUnown: applyFormat("$1", "$1") else: |