Skip to content

fix: support full 64-bit integer range for number inputs in uint64/ctor - #15476

Merged
kgryte merged 3 commits into
stdlib-js:developfrom
impawstarlight:fix/uint64-ctor
Sep 24, 2026
Merged

kgryte merged 3 commits into
stdlib-js:developfrom
impawstarlight:fix/uint64-ctor

Conversation

@impawstarlight

@impawstarlight impawstarlight commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • Lifts the restriction on number arguments to the Uint64 constructor to allow unsafe integers upto 2^64-1.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

N/A.


@stdlib-js/reviewers

@impawstarlight
impawstarlight requested a review from a team September 23, 2026 22:05
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 23, 2026
@stdlib-bot

stdlib-bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
number/uint64/ctor $\\color{red}581/641$
$\\color{green}+0.00\\%$
$\\color{red}48/51$
$\\color{green}+0.00\\%$
$\\color{red}9/11$
$\\color{green}+0.00\\%$
$\\color{red}581/641$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@impawstarlight impawstarlight added the Enhancement Issue or pull request for enhancing existing functionality. label Sep 23, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Sep 24, 2026
Comment thread lib/node_modules/@stdlib/number/uint64/ctor/test/test.js Outdated
Comment thread lib/node_modules/@stdlib/number/uint64/ctor/test/test.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>

for ( i = 0; i < values.length; i++ ) {
z = values[i];
z = BigInt( values[i] );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear why this change is necessary, but I'll defer to your judgment.

@impawstarlight impawstarlight Sep 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because calling toString on an unsafe integer truncates the trailing digits to zero even though those digits are exactly representable in double, which we can see with toPrecision. But there's no way to use toPrecision with arbitrary radix, so we need rely on BigInt for precise serialization with specified radix in this test.
Screenshot_20260924_145703

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation.

@kgryte kgryte Sep 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like #.toString behavior is odd here and a likely source of confusion, especially when used in the REPL. Maybe we should add a dedicated utility to number/float64/to-exact-string (name?) to provide something more robust.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a bit of back-and-forth with ChatGPT, I understand why #.toString behaves as it does (namely, serialize to the shortest representation which generates the exact same double). But, for usage in the REPL, this can lead to misleading results.

Signed-off-by: Athan <kgryte@gmail.com>
@kgryte
kgryte merged commit 93dfa49 into stdlib-js:develop Sep 24, 2026
12 checks passed
@impawstarlight
impawstarlight deleted the fix/uint64-ctor branch September 24, 2026 09:06
@kgryte kgryte added the Needs Follow-up Pull request requiring one or more follow-up actions. label Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Issue or pull request for enhancing existing functionality. Needs Follow-up Pull request requiring one or more follow-up actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants