A while back I was developing a workflow scheduler. However the run duration kept coming back negative. The runs kept finishing like 15 seconds before they started. Eventually I figured out why; the company had configured a policy to use their custom NTP server, but it was 16.7 seconds off. So my Windows laptop’s time was in the future, but the WSL VM (which ran the program) used another NTP server and was correct. In the end I just added a bodge that made the program request the time from an external server on startup to calculate an offset.


Ok, I understand the issue but I don’t understand your embarrassment from it. You didn’t write the initial bug.
Btw, a faster way to check if a value is even is to just do a bitwise AND on bit 0 (if it is an integer, though it needs to be an integer for modulus to work anyways).
In many languages it looks like:
if ( val & 1 ) { \ it is odd }
Division is a multi-cycle operation but bitwise comparisons are simple enough to be done in a single cycle, or could even be thrown on to instructions as a free extra that doesn’t add any extra cycles (eg any instruction with a bit mask, though it depends on the implementation as to whether it’s done for 0 extra cycles or more).
Doesn’t really matter for a one off operation like halving the value of video display parameters, but if you have a loop that needs to check a lot of them, the bitwise and will pull ahead.
And if you’re thinking “well we need to divide by 2 anyways and the modulus is available from that operation as long as the compiler sees it should save the result and the modulus”, a bitwise shift right (non-circular) of 1 is also way faster than divide by 2.
Both of these can also be generalized for any power of 2, if necessary.