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

XS rounds some numbers incorrectly #944

Open
gibson042 opened this issue Oct 15, 2022 · 1 comment
Open

XS rounds some numbers incorrectly #944

gibson042 opened this issue Oct 15, 2022 · 1 comment
Labels
confirmed issue reported has been reproduced

Comments

@gibson042
Copy link

gibson042 commented Oct 15, 2022

Environment: XS 13.0.0 32 4

Description
Converting to numbers that require rounding from a literal or string is inconsistent with the ECMAScript specification.

Steps to Reproduce

[9007199254740993, +"9007199254740993"]

Actual behavior

[9007199254740994, 9007199254740994]

Expected behavior

[9007199254740992, 9007199254740992]

When rounding, ties should resolve to the even IEEE 754 significand: https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#number-value-for (for NumericLiteral via EvaluationNumericValueRoundMVResult → [because the decimal representation has 20 or fewer significant digits] 𝔽the Number value for x and for string via StringToNumberStringNumericValueRoundMVResult).

@phoddie phoddie changed the title XS appears to round numbers incorrectly XS rounds some numbers incorrectly Oct 20, 2022
@phoddie phoddie added the confirmed issue reported has been reproduced label Oct 20, 2022
@phoddie
Copy link
Collaborator

phoddie commented Oct 20, 2022

We took a quick look into this issue. The conversion from string to number is done using strtod from the venerable dtoa library. Given the complexity of implementing that correctly, you'll understand that we try to avoid modifying that code. Some possibilities:

  • A mismatch between the behavior required by Ecma-262 and what is implemented by strtod
  • XS is using strtod incorrectly
  • XS is configuring strtod incorrectly for this case

At one point other engines also used the same library. I'm not sure if that's still the case. If they do, that would be a good reference point to see how they are handling this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced
Projects
None yet
Development

No branches or pull requests

2 participants