Skip to content

fix: parseInt/parseFloat return NaN for non-numeric strings#257

Merged
cs01 merged 2 commits intomainfrom
fix/parseint-nan
Mar 12, 2026
Merged

fix: parseInt/parseFloat return NaN for non-numeric strings#257
cs01 merged 2 commits intomainfrom
fix/parseint-nan

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • parseInt("abc") returned 0 instead of NaN — now correctly returns NaN
  • parseFloat("xyz") had the same bug — also fixed
  • Root cause: strtol/strtod return 0 for unparseable input; we now check the endptr to detect if any characters were consumed
  • parseInt("") also now correctly returns NaN

Test plan

  • New test fixture builtins/parseint-nan.ts covers valid, invalid, empty, negative, and zero inputs
  • npm run verify:quick passes (tests + Stage 1 self-hosting)

🤖 Generated with Claude Code

@cs01 cs01 merged commit 86f5d60 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/parseint-nan branch March 12, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant