-
Notifications
You must be signed in to change notification settings - Fork 29
Update to new ComputeNudgeWindow spec text #636
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
base: main
Are you sure you want to change the base?
Conversation
d3594c8 to
9a445cb
Compare
|
This now passes tests, but I'm not entirely sure of the impl |
9a445cb to
6394a10
Compare
|
This fails other tests (due to hitting assertions, I think) |
nekevss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a couple notes after taking a glance.
Are you still looking into the failures mentioned above?
| // 7. Let r1 be nudgeWindow.[[R1]]. | ||
| // 8. Let r2 be nudgeWindow.[[R2]]. | ||
| // 9. Set startEpochNs to nudgeWindow.[[StartEpochNs]]. | ||
| // 10. Set endEpochNs to nudgeWindow.[[StartEpochNs]]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, spec bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tc39/proposal-temporal#3191 - should have been caught in review, but anba caught it a bit later
| (dest_epoch_ns - start_epoch_ns.0) as f64 / (end_epoch_ns.0 - start_epoch_ns.0) as f64; | ||
| // 14. Let progress be (destEpochNs - startEpochNs) / (endEpochNs - startEpochNs). | ||
| // 15. Let total be r1 + progress × increment × sign. | ||
| let progress = (dest_epoch_ns.0 - start_epoch_ns.0) as f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this actually may be a candidate for using the Fraction type to compute
|
|
||
| impl UnsignedRoundingMode { | ||
| /// <https://tc39.es/proposal-temporal/#sec-applyunsignedroundingmode> | ||
| pub(crate) fn apply(self, x: f64, r1: i128, r2: i128) -> i128 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I think at the point that we are passing x as a f64, we should just pass r1 and r2 as a f64 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't, because r1 and r2 are the actual returned values, and that would potentially change the produced mathematical value.
On the other hand, the only thing that matters about x is which side of r1 + r2 / 2 it is. That's easier to get right.
We should probably use a Fraction type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't, because r1 and r2 are the actual returned values, and that would potentially change the produced mathematical value.
Ah shoot, true.
On the other hand, the only thing that matters about x is which side of r1 + r2 / 2 it is. That's easier to get right.
Yeah, that's what IncrementRounder was relying on.
| temporal_assert!(r1.abs() as f64 <= total.abs() && total.abs() < r2.abs() as f64); | ||
| // b. Let roundedUnit be ApplyUnsignedRoundingMode(abs(total), abs(r1), abs(r2), unsignedRoundingMode). | ||
| // TODO: what happens to r2 here? | ||
| unsigned_rounding_mode.apply(total.abs(), r1.abs(), r2.abs()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, huh. Yeah, it'd probably be worth taking a second pass at rounding given some of the changes to the specification.
I'd really prefer to stay away from f64 if possible, but it might not be with all the changes that have been made to the spec since this was first written.
| } | ||
| } | ||
|
|
||
| impl UnsignedRoundingMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It would be nice to have some unit tests for this.
No, but they should be replicable by copying the tests. |
6394a10 to
acb80b0
Compare
|
The failures were due to a missing <=. Fixed. |
|
And that fixes the crashes. Would still like to see if this can be written without floats, but I don't have time to do that myself. |
Fixes #635
Updates to tc39/proposal-temporal#3172
This passes the test, but it fails other tests. The problem is probably that IncrementRounder isn't written in terms of r1 and r2. @nekevss, I don't understand the full purpose of IncrementRounder being written the way it is: mind having a look?The new spec text changes how r1 and r2 are computed, and they're passed down to IncrementRounder in the spec but not the code, so I assume that IncrementRounder is recomputing them somehow from the inputs.I wrote this to not use IncrementRounder. I'm not 100% sure if the implementation is correct when it comes to how it handles mathematical values.