Skip to content

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

Merged
merged 13 commits into from
Jun 20, 2024
Merged

Conversation

nekevss
Copy link
Member

@nekevss nekevss commented Jun 15, 2024

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 a i128 and not a f64 for safety as well as the new duration rounding algoritms. This means we need to be able to round both i128 and f64 for the library. So this branch currently updates the approach to rounding to allow handling of i128 and f64 at the same time, which allows NormalizedTimeDuration to be an i128.

@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 where T is a u64 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 welcomed 😄

Actually found the bug. It was converting NormalizedTimeDuration -> fractional_days

@nekevss nekevss force-pushed the update-rounding-approach branch from 0db56fc to 8961afe Compare June 16, 2024 01:43
@nekevss nekevss marked this pull request as ready for review June 16, 2024 04:37
@nekevss nekevss added the C-enhancement New feature or request label Jun 16, 2024
// 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.
Copy link
Member

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

Copy link
Member Author

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
Comment on lines 106 to 104
fn is_cardinal(&self) -> bool {
self.result_floor().rem_euclid(2) == 0
}
Copy link
Member

@jasonwilliams jasonwilliams Jun 16, 2024

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?

Copy link
Member Author

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.

Copy link
Member

@jasonwilliams jasonwilliams left a 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

@nekevss nekevss requested a review from jedel1043 June 16, 2024 21:24
@jedel1043 jedel1043 added the C-internal Internal library improvements label Jun 16, 2024
@nekevss nekevss force-pushed the update-rounding-approach branch from 03d0642 to 0f105f6 Compare June 17, 2024 00:34
@nekevss nekevss requested a review from jedel1043 June 17, 2024 01:03
@nekevss nekevss force-pushed the update-rounding-approach branch from b44fb0e to be58fb1 Compare June 20, 2024 02:07
Copy link
Member

@jedel1043 jedel1043 left a 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.

@jedel1043 jedel1043 merged commit fc078da into main Jun 20, 2024
5 checks passed
@nekevss nekevss deleted the update-rounding-approach branch June 20, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request C-internal Internal library improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants