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: Add missing checks before calling ApplyUnsignedRoundingMode #2884

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

anba
Copy link
Contributor

@anba anba commented Jun 5, 2024

Changes:

  • I've inserted abs for all arguments passed to ApplyUnsignedRoundingMode to ensure the r1 ≤ x < r2 requirement in ApplyUnsignedRoundingMode is fulfilled.
  • Furthermore startEpochNs and endEpochNs are now required to be correctly ordered. This ensures that progress is a proper fraction. (If it's not a proper fraction, then abs(total) can be larger than abs(r2), which is invalid for ApplyUnsignedRoundingMode.)
  • Also fixes NudgeToCalendarUnit: Wrong roundedSign for (roundedUnit - total == 0)? #2893 by comparing roundedUnit against abs(r2).

@anba
Copy link
Contributor Author

anba commented Jun 5, 2024

Instead of checking progress, it should also be possible to check that destEpochNs, startEpochNs, and endEpochNs are correctly ordered.

@anba
Copy link
Contributor Author

anba commented Jun 6, 2024

Hmm, it looks like 9be3190 needs more checks to guarantee that r1 ≤ total < r2 holds when the inputs are negative.

ApplyUnsignedRoundingMode requires `r1 ≤ t < r2`, see step 2. Add
missing checks to ensure this requirement is fulfilled when called from
NudgeToCalendarUnit.

Drive-by change:
Update RoundNumberToIncrement to call GetUnsignedRoundingMode with
correct spec type.

Also fixes tc39#2893.
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks.

I think without custom calendars, the RangeErrors may be changed to assertions, but I'll merge this first and update that if necessary when merging the PR removing custom calendars.

Implements the extra checks and assertions from the previous commit, as
well as the use of abs() to simplify the didExpandCalendarUnit check and
to satisfy the requirements of ApplyUnsignedRoundingMode.
@ptomato
Copy link
Collaborator

ptomato commented Jun 28, 2024

I've made the corresponding changes in the reference code as well, to exercise them on the test262 suite.

@ptomato ptomato merged commit 341a64c into tc39:main Jun 28, 2024
5 checks passed
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.

NudgeToCalendarUnit: Wrong roundedSign for (roundedUnit - total == 0)?
2 participants