fix printing negative zero in JS backend (#16505)
This commit is contained in:
parent
732419ae90
commit
89a2390f8b
2 changed files with 33 additions and 1 deletions
|
|
@ -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`)){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue