-
Notifications
You must be signed in to change notification settings - Fork 19
Update increment rounding functionality #53
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
Conversation
0db56fc
to
8961afe
Compare
// NOTE(nekevss): Is it worth returning a `RangeError` below. | ||
debug_assert!(nanoseconds.abs() <= MAX_TIME_DURATION); | ||
Self(nanoseconds) | ||
} | ||
|
||
// NOTE: `days: f64` should be an integer. |
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.
Is this going to be changed in a follow up? I guess there's too many call sites right now to change in this PR
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.
More than likely, yes. I'm pretty sure I wanted to be able to verify in all cases that it would be days: u64
or some equivalent before making the change.
src/rounding.rs
Outdated
fn is_cardinal(&self) -> bool { | ||
self.result_floor().rem_euclid(2) == 0 | ||
} |
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.
Is this a correct name? Aren't all positive numbers cardinal rather than just even ones?
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.
Yeah, the name doesn't match real well. The name was a bit more specification leaning, but definitely ambiguous.
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.
Im sure @jedel will know more about the changes, but LGTM
03d0642
to
0f105f6
Compare
b44fb0e
to
be58fb1
Compare
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.
Overall it looks good. Maybe in the future we'll be able to move some invariants into the typesystem (some kind of NonNanF64
would be great), but that can be added incrementally.
This is still technically a draft. Although due to Duration rounding updates, I'd almost be in favor of merging this depending on feedback, primarily due to potential scope creep.
Overview:
NormalizedTimeDuration
needs to be ai128
and not af64
for safety as well as the new duration rounding algoritms. This means we need to be able to round bothi128
andf64
for the library. So this branch currently updates the approach to rounding to allow handling ofi128
andf64
at the same time, which allowsNormalizedTimeDuration
to be ani128
.@jedel1043 This is the rounding functionality I had mentioned on the GC call. If you have any thoughts on the API, let me know. There's probably an argument for a
PositiveIncrementRounder
that whereT
is au64
instead of adding*_as_positive
methods on the current approach.Tests / Scope Creep
Currently, this does break a couple unit tests for duration rounding, but I'm fairly certain that those have to do with truncation or some other issue in the duration rounding algorithm not the increment rounding itself (added some sanity unit tests to rounding), so I might look into this further.This goes back to the scope creep I mentioned above. I'm trying not to make too much of an omnibus PR, and the duration rounding as a whole needs to be overhauled to the new algorithms. But the new algorithms need rounding and😄NormalizedTimeDuration
updated, so I'm not entirely sure whether it's worth fixing the current tests with the current algorithm when the fixes can be completed while updating to the new algorithm. Not entirely sure, so any thoughts would be welcomedActually found the bug. It was converting
NormalizedTimeDuration
->fractional_days