Re: Long term usage of TIME

Discussions related to mathematics, numerical methods, graph plotting etc.
Hated Moron

Re: Long term usage of TIME

Post by Hated Moron »

On 13/09/2022 17:49, bb4w@desportes.net wrote (cross-posted from Discussion Group):
I assume that TIME is considered as returning a signed integer when using it in comparisons as suggested in the documentation. (e.g. IF TIME>somevalue% THEN..)

In the situation of having several concurrent and asynchronous timeouts relying on TIME -- which are not regularly ticking timers that could be managed through TIMERLIB calls -- then after about 248 days of continuous operation, the above statement ("IF TIME>somevalue% THEN..") will not operate as wanted, i.e. timeouts won't work anymore.(for the next 248 days ;-) , as TIME would return a negative value.

Setting TIME to 0 at some point is not an option, as any currently running timeout will then be affected.

What options do I have?
Expecting any program to keep working continuously for more than 248 days is, shall we say, optimistic! So it's not something that I would worry too much about, personally.

But if this is a genuine concern, one way to tackle it is to fabricate a function which returns a 64-bit value of time rather than the usual 32-bit value:

Code: Select all

      DEF FNtime64
      LOCAL T%
      PRIVATE t%, o%%
      T% = TIME
      IF T% < t% o%% += 2^32
      t% = T%
      = T% + o%%
(Because of the phpBB bug this code listing will not be formatted correctly at the Discussion Group. Please click through to the original forum message to read it.)