-
Notifications
You must be signed in to change notification settings - Fork 18
Signed/Unsigned Inner Types #7
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
Comments
This is inaccurate. In fact, a signed result of the wrapping arithmetic is important. Otherwise, Instances cannot be ordered. |
If it is absolutely necessary for the difference between two Perhaps the inner types could be unsigned and only be cast to signed in the case of getting the difference of |
Why did you change from signed to unsigned in #22? It sounded like in this issue you were saying that signed durations are good. I would strongly agree that Durations should be signed. Algebraically, durations can be negative, so it's surprising that (by default) I can't create a duration that represents "1 minute ago". I.e., I can subtract a Duration from an Instant, but I can't add a negative Duration: |
Uh oh!
There was an error while loading. Please reload this page.
I began this journey after finding that the core::Duration was an unsigned value. I then investigated the
time
crate and found that while it does have signed Duration, it is focused more toward "wall-clock" time considerations. This led me to great this project.I began my development with the use-case of a non-wrapping timer (typically chaining two 32-bit peripheral timers in a microcontroller). However, if this project is to be compatible with wrapping timers, that may fundamentally change its design.
Signed durations can be useful when calculating the difference between two instances. It allows the subtraction to be done in either order returning a logical result. For example, in the expression
x - y
, ifx
is earlier thany
, a negative duration is returned. However, if wrapping timers are to be supported, a negative duration will never be returned as subtracting a "higher-value" instance from a "lower-value" assumes the timer wrapped, and a positive duration is returned.The text was updated successfully, but these errors were encountered: