negative microseconds

I just ran into the “microseconds rollover” caveat. But it didn’t behave the way I thought it would. Instead of the value restarting at zero, calling microseconds started giving only negative values. Is that the expected behavior on Mac for a microseconds rollover?

of course. It’s a 64bit integer and on overrun it will turn to negative.

Okay. But as far as I can see, it’s type is a Double. The LR isn’t entirely clear there.

In any case, I need to figure out how to handle the rollover situation. It appears the only way to deal with it is to restart the machine.

Or have a method for getting microseconds that checks for a negative value and corrects it to return a positive value, but then that slows down the task of getting microseconds, and the whole point is to get accurate clock information.

Is there a better way to get an accurate internal clock time, that doesn’t have this problem?

As far as I know it’s internally a 64bit for nanoseconds.
But I may wrong. Because that would require 200+ years to overflow.

what do you do with it?

I normally store value later and calculate difference with

abs(NewMicroseconds-OldMicroseconds)

If I always use abs(microseconds) will the overflow condition behave like the normal condition? It seems not. I could not figure out the behavior of the values in the overflow condition.

How are you ever expericencing an over flow with microseconds?
Computers have not even existed that long… (my calculations say it overflows every 293 thousand years)

All I know is that microseconds started returning negative values. I quit Xojo and restarted. No change. I had to restart the machine to fix it.

Seems like it’s a UINT64 internally: https://developer.apple.com/library/mac/qa/qa1398/_index.html I wonder if Xojo is not doing the conversion to double properly?

Thanks for the link. I’ll try to write a declare for this … unless anyone else has already done it, or there is something in MBS?

Also sounds like I should file a feedback report, yes?

MidiPacketMBS.CurrentTime is a function to query the current time on Mac as UInt64.

Yes, if you are sure it’s an issue.

There was a (possibly related) issue reported w.r.t. Random - the seed value seemed to be rolling over there, too:
<https://xojo.com/issue/11528>
Could be the same thing (I was using Microseconds() to seed Random.seed)

Where you able to reproduce this ?