Best practice for handling very large, rapidly increasing variables?

[Edit: Sorry I didn't make this clear originally, this particular scenario with the encoders is just an example, I'm looking for advice for best practice for dealing with overflows. Yes, I could avoid the problem altogether in this situation, but there might come a time when I can't avoid the problem and I'd like to know how to overcome it when/if I get there. ]
I have a robotic platform with built-in wheel encoders that have a resolution of 138 ticks/mm (yes mm, not cm) and a top speed of 1500mm/s, meaning that if I use a signed long to keep track of ticks, I can drive forward for about ~3 hours before my variable overflows, throwing off calculations and such. There are a couple ways I know of that I could solve this problem.
One I could simply use a signed long long instead, increasing my run time to like 1.5million years, but I know 64-bit stuff in arduino is expensive (I'm using a Teensy 4.0 though, so I'm not sure this would be an issue).
Two, I could write a conditional to catch the overflow and compensate for it, not exactly sure what this would be, but I'm sure it's possible.
I'm certain there are other ways to handle this too, but those are the ones that came to mind. Searching around for best practice tips on this basically turned up either "if it's unsigned it'll work itself out", which isn't relevant for my signed variable, or "do your best to avoid this happening", which is not really and answer at all.
What would be the 'best practice' solution in this situation and why is one method better or worse than another?
Apologies if this is a duplicate of another thread somewhere, I didn't see any, but if it is I can remove this.

All that text and I do not see a description of what you are attempting to accomplish. What other ways have you investigated?

Teensy 4.0 is super fast. Just use long long and worry about a more clever solution later if it turns out you have to.

I don’t know exactly what you mean by “tick”, but 138 ticks / mm X 1500 mm / s = 207000 ticks / s.

Assuming each “tick” is a cycle on a quadrature encoder, that’s 828,000 edge transition per second.

Have you confirmed you can process them at that rate?

That's 7 micron precision over 16 km of travel. I'd really like to see a pic if it has positioning repeatable to that level. on the other hand, if you are using other information for positioning, you could update your longs to the other-derived position whenever you're more than some distance (1km? 10km?) from zero.

I'm simply keeping track of the encoder ticks as the robot drives, but that's not really relevant, I'm just using it as an example of an input that counts up really fast and would overflow a typical signed long variable in a reasonable time frame.
The two methods I mentioned are the only two I've tried, and both work, I'm just wondering what the best practice method would be.

Yes, I have triple checked that the count doesn't miss any ticks.
Yeah 'ticks' being the cycle on a quadrature encoder, such that turning it one way makes 'ticks' count up and turning it the other way makes 'ticks' go down. Specifically, it's the output of encoder.read() in the QaudEncoder.h teensy library.

That depends on what you are trying to accomplish.

All the blather about how to avoid overflow or rollover problems is based on the idea that you only need relative measurements, none of which woukd be so large as to overflow a calculation.

So for example millis() works forever if you are only concerned about timing ten minutes or ten days.

Do you need absolute measurement to the sub millimeter over 16 km?

a7

That number is straight from the datasheet for the robot platform, and old ActivMedia Robotics Pioneer P3AT. Obviously it's dependent on a lot of mechnical factors like tire pressure, and it's not actually accurate to 7 micron, but that's how many ticks I get if I drive forward 1m.
I don't have any other absolute positioning method, just an IMU and very rough camera.
This was more of an example anyways, I'm just looking for some best practice advice.

No I don't need absolute positioning over 16km, but I might need it for some other project in the future, so I'd like to know what to do then. The robot is just an example, not the actual problem. I didn't communicate that very well in my post, my apologies.

At the absolute most basic level, I'm just trying to track the position of a rotary encoder as it spins. Sorry, I'm not sure what else I can give you as far as what I'm trying to accomplish.

You could use two 32- bit variables, one for the actual ticks, and the other that gets incremented or decremented when the first overflows or underflows.

The "best practice" method is to design the problem out of existence. If a 64-bit variable will solve the problem until the sun goes supernova, then use a 64-bit variable and call it good.

Which would be implementing your own uint64_t .... just with more overhead.

OK IC. Just keep in mind the relative (see what I did there) ease with which an unsigned long variable can use subtraction and end up with a meaningful valid difference between two readings.

As I said, millis() is the classic use case.

a7

Best practice is avoid the problem. Count mm ticks till you get 100, then reset and add 1 to cm. When that gets to 100, reset and add 1 to meters.