Skip to content

Number.toString returns its string, and converts in any radix - #56

Merged
ASDAlexander77 merged 1 commit into
mainfrom
number-tostring-return
Oct 29, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
number-tostring-return

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

  • Number.toString had no return: callers read whatever was left in the result register. Under gc that happened to be the string; under rc, none and own new Number(5).toString() crashed.
  • number.toString(radix) converts in radix 2 to 36 as JavaScript does. Radix 16 was C's %a (0x1.fe00000000000p+7 for 255) and any other radix was ignored. A power-of-two radix gives every digit; another radix is cut at 52 fraction digits.

Independent of ASDAlexander77/TypeScriptCompiler#728.

Tests

  • tests/number_object_tostring.ts: new Number(5).toString(), radix 16/2/36, a negative fraction, zero, (0.1).toString(2)
  • Windows: gc 178, rc/none 177 (+1 skipped), own 167 (+11 skipped)

🤖 Generated with Claude Code

- Number.toString had no `return`: the caller read what was left in the result register,
  which under gc happened to be the string and under rc, none and own crashed.
- number.toString(radix) converts in radix 2 to 36 as JavaScript does: 16 was C's "%a"
  (0x1.fe00000000000p+7 for 255) and any other radix was ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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