Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: clarify string representation of numbers with radix ≠ 10 #2854

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

michaelficarra
Copy link
Member

@michaelficarra michaelficarra commented Aug 13, 2022

Fixes #2847 by adding a radix parameter to Number::toString.

/cc @bathos

spec.html Show resolved Hide resolved
Copy link
Contributor

@bakkot bakkot left a comment

Choose a reason for hiding this comment

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

LGTM other than comment but I want to wait for @syg's approval as well.

@bathos
Copy link
Contributor

bathos commented Aug 16, 2022

@michaelficarra %Bigint.prototype.toString% uses the same “should be a generalization” text and points at BigInt::toString. As far as I can tell the algorithm-in-practice aligns with Number-when-not-base-10. Would it make sense (and would it be desirable) for them to point to a common algorithm that’s agnostic to the specific numeric language type?

(This PR already stands on its own with plenty of value, so I’m not suggesting it should address anything related to %BigInt.prototype.toString% — just curious about how that could end up looking.)

Copy link
Contributor

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I like the improved generality and precision, and this does a decent job of containing the decimal-specific scale weirdness. That said, I do wonder if the latter could be achieved even better, e.g.

1. If _radix_ ≠ 10 or _n_ is in the inclusive interval from -5 to 21, then
  1. If _n_ ≥ _k_, return the string-concatenation of…
  1. If _n_ > 0, return the string-concatenation of…
  1. Else,
    1. Assert: _n_ ≤ 0.
    1. Return the string-concatenation of…
1. Assert: _radix_ is 10.
1. …

spec.html Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@michaelficarra
Copy link
Member Author

@gibson042 Thanks for the suggestions. I took all of them. Please re-review to check my work.

@bathos Agree, we could do something similar about %Bigint.prototype.toString%. Can you open an issue to track it? I don't think they should share an algorithm, but we can at least make a similar clarification.

spec.html Show resolved Hide resolved
spec.html Show resolved Hide resolved
@michaelficarra
Copy link
Member Author

Thanks @jmdyck. Done.

spec.html Show resolved Hide resolved
spec.html Show resolved Hide resolved
@michaelficarra michaelficarra added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Aug 17, 2022
@ljharb ljharb changed the title fixes #2847: clarify string representation of numbers with radix ≠ 10 Editorial: clarify string representation of numbers with radix ≠ 10 Aug 18, 2022
@ljharb ljharb merged commit 868fe7a into main Aug 18, 2022
@ljharb ljharb deleted the GH-2847 branch August 18, 2022 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How “implementation-defined” is %Number.prototype.toString% meant to be?
7 participants