fix(dollar): $NaN -> "NaN", $Inf -> "Infinity" only when js (#24695)

ref nimpylib/pylib#44

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
(cherry picked from commit 91e8e605d0)
This commit is contained in:
lit
2025-02-20 06:03:28 +08:00
committed by narimiran
parent 1380084f57
commit c8a030a902

View File

@@ -110,6 +110,10 @@ when defined(js):
}
if (Number.isSafeInteger(`a`))
`result` = `a` === 0 && 1 / `a` < 0 ? "-0.0" : `a`+".0";
else if (isNaN(`a`)) // Number.isNaN is since ES6
`result` = "nan"; // or it'll be "NaN"
else if (!isFinite(`a`)) // Number.isFinite newer but unnecessary here
`result` = `a` > 0 ? "inf" : "-inf"; // or it'll be [-]Infinity
else {
`result` = `a`+"";
if(nimOnlyDigitsOrMinus(`result`)){