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

Number::toString seems to require accuracy #2444

Closed
bergus opened this issue Jun 24, 2021 · 0 comments · Fixed by #2450
Closed

Number::toString seems to require accuracy #2444

bergus opened this issue Jun 24, 2021 · 0 comments · Fixed by #2450

Comments

@bergus
Copy link

bergus commented Jun 24, 2021

I think #2007 or #1135 broke the Number::toString abstract operation, now specifying a mathematical value equality where originally a floating point ("Number value") equality was meant.

In ES6, step 5 did still read as

Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, the Number value for s × 10n−k is m, and k is as small as possible.

At some point this changed to the current reading of

Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, s × 10n - k is ℝ(x), and k is as small as possible.

This sounds like s × 10n - k is a mathematical value, and to fulfill this equality exactly, s would need to be a quite long integer - no rounding permitted in choosing these values, and therefore no inaccuracy. This doesn't make sense to me in light of Note 1 ("The least significant digit of s is not always uniquely determined") and Note 2 ("For implementations that provide more accurate conversions […], choose the value of s for which s × 10n - k is closest in value to ℝ(x)").

I believe that instead this sentence should be

Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, 𝔽(s × 10n - k) is x, and k is as small as possible.

and similiar for the more accurate version in Note 2

Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, 𝔽(s × 10n - k) is x, and k is as small as possible. If there are multiple possibilities for s, choose the value of s for which s × 10n - k is closest in value to ℝ(x).


For reference, this came up in answering the StackOverflow question Why does Number(“x”) == BigInt(“x”) … only sometimes?.

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 a pull request may close this issue.

1 participant