Best way to represent long numbers without losing accuracy and minimal size

I’m trying to represent timestamp of a set of data in nanosecond accuracy in a root file. Converting a normal human readable time format(yyyy/mm/day/hr/min/sec) to TtimeStamp results in a 32 bit representation of it.

Now I have the 32 bit TtimeStamp, I would now add the other 9 digits after the 32bit TtimeStamp which would probably increase the numbers of possible digits up to 19.

I thinking of splitting it into 2 sets of value and save it to a root file which may required me to combined that 2 values into 1 to get the true time in nanoseconds.

Anyone have any good idea or better way of doing this without sacrificing its accuracy?

*Mostly trying to do this in C++. IF you have better ways in pyroot i would be also interested to hear how you deal with it in python.

A TTimeStamp contains

struct timespec
   {
      time_t   tv_sec;   // seconds
      long     tv_nsec;  // nanoseconds
   }

That should be sufficient?

The modern C++ way is to use a time_point with nanoseconds precision:
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp;

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.