-
Notifications
You must be signed in to change notification settings - Fork 14
✨ Add rollover_t
#171
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
✨ Add rollover_t
#171
Conversation
7e3e891
to
b97aec5
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.
i'm worried about the fact that zero < half
and half < zero
both evaluate to true. is there a way we can avoid this? it feels very wrong.
@elbeno: I think I remember what I did...it was with signed integers, but let's pretend that signed overflow is defined behavior for a moment: bool operator<(auto a, auto b) {
retutrn (a - b) < 0;
} That implementation takes care of the wraparound case and there is no case in which |
This is how it should work for bool operator<(uint32_t a, uint32_t b) {
retutrn (a - b) >> 31;
} In 2s complement signed integers, a number is negative if the msb is set. This function does the equivalent check for |
You're right - and that's exactly equivalent to what I've written. |
You're right! Ok....I need some more work to wrap my brain grapes around this one... 🧠🍇 |
69eb768
to
b7e612d
Compare
Problem: - When dealing with a timer register that rolls over, it is useful to have a type that knows how to handle that. Solution: - Add `rollover_t`. - `rollover_t` behaves like an unsigned integral type, with interesting comparison semantics.
Problem:
Solution:
rollover_t
.rollover_t
behaves like an unsigned integral type, with interesting comparison semantics.