Closed henrikssn closed 2 years ago
Hi, this looks correct to me. Instant supports time which can roll over, so the maximum range is MAX/2 - 1.
I think the documentation needs clarification here
And thanks for bringing this to my attention!
Interesting, thanks for the explanation! What do you think about adding an Instant::MAX constant? :)
I see what you want, but it would be difficult.
As every instant is relative another instant there is no absolute MAX
value, it's simply MAX/2 - 1
that is the maximum relative offset that is valid without overflow.
Does that make sense?
Hmm, I think so. If we would define u32::MAX/2 - 1
as MAX, would it then be true that
Instant::MAX + Instant::from_ticks(1) > Instant::MAX
That is correct.
You can run this test to verify:
#[test]
fn yolo() {
let max = Instant::<u32, 1, 1>::from_ticks(core::u32::MAX / 2 - 1);
let maxpone = Instant::<u32, 1, 1>::from_ticks(core::u32::MAX / 2);
assert!(maxpone > max);
}
I try this code on a thumbv7em-none-eabihf target:
Output:
Since
u32::MAX > 1000
, something seems to be wrong inside ofconst_cmp
?