fix printing negative zero in JS backend (#16505)

This commit is contained in:
flywind 2020-12-29 08:50:22 -06:00 • committed by GitHub
commit 89a2390f8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -495,11 +495,13 @@ proc negInt64(a: int64): int64 {.compilerproc.} =
proc nimFloatToString(a: float): cstring {.compilerproc.} =
## ensures the result doesn't print like an integer, i.e. return 2.0, not 2
# print `-0.0` properly
asm """
function nimOnlyDigitsOrMinus(n) {
return n.toString().match(/^-?\d+$/);
}
if (Number.isSafeInteger(`a`)) `result` = `a`+".0"
if (Number.isSafeInteger(`a`))
`result` = `a` === 0 && 1 / `a` < 0 ? "-0.0" : `a`+".0"
else {
`result` = `a`+""
if(nimOnlyDigitsOrMinus(`result`)){