Skip to content

Conversation

@mark9064
Copy link
Member

Imagine the tick count wraps around at 1000, the hold time is set to 150, and the current time is 900. With the current code the comparison becomes 900 > 900 + 150 which is 900 > 50 as (1050 % 1000 = 50) so the condition will immediately be true.

With the new code, the comparison becomes 0 > 150 so there is no problem.

@github-actions
Copy link

Build size and comparison to main:

Section Size Difference
text 374544B -16B
data 948B 0B
bss 63488B 0B

@mark9064 mark9064 added the maintenance Background work label Oct 20, 2025
@mark9064 mark9064 added this to the 1.16.0 milestone Oct 20, 2025
@minacode
Copy link
Contributor

minacode commented Nov 5, 2025

Don't you get the same problem now, just the other way around?

1050 gets 50 and then you check 50 - 900 > 150 which can never be true.
Or is 50 - 900 negatively overflowing to some large positive number as well?

@mark9064
Copy link
Member Author

mark9064 commented Nov 5, 2025

Yeah you get that negative wraparound. So 50 - 900 is 150

Crucially, t2 - t1 will always give you the correct duration between them in ticks (provided t2 is in the future from t1, and less than one wraparound of ticks has elapsed). When you know the duration, you can compare that with a constant without issue

@mark9064 mark9064 merged commit 3a1f4fe into InfiniTimeOrg:main Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Background work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants