From bb982c644b8e3e8a59cf2c60b28ff91741c7dc9b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 27 Apr 2020 08:33:03 -0700 Subject: `$(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 --- compiler/jsgen.nim | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'compiler') 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: -- cgit 1.4.1-2-gfad0