[1] https://github.com/coreutils/coreutils/blob/master/src/yes.c
[1] https://github.com/coreutils/coreutils/blob/master/src/yes.c
But of course GNU is kind of notorious in this regard. Compare their `yes` to OpenBSD's. It's night and day.
https://github.com/openbsd/src/blob/master/usr.bin/yes/yes.c
What do people that need higher resolution use? And the people that don't care about that amount, do they pay the performance penalty?
Every physical or humane value is hard to some extent.
For reference, the universe is about 13.787 billion years old [0]. That's about 13.787 * 10^9 * 365 * 24 * 3600 = 4.348 * 10^17 seconds, which (I think?) is a 59-bit number [1]. 10ths of a second will require 62 bits, which is right about at the edge of what a 64-bit signed integer will allow.
If you want milliseconds, you'll need at least 69 bits. For nanoseconds, you'll need at least 89 bits.
So you'll either need an integer type that's wider than what's natively supported in most hardware (thus potentially sacrificing performance), or you'll have to sacrifice precision.
[0]: https://en.wikipedia.org/wiki/Age_of_the_universe
[1]: https://www.wolframalpha.com/input/?i=13.787+*+10%5E9+*+365+...
I'm mostly kidding. But if you're thinking of representing nanoseconds since the big bang, the wait for 128-bit CPUs is not very long...
[0] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html
Since larger than 64 bit ints are a disaster for portability, the reasonable solution is to go with a 64 bit signed seconds, 32 bit nano offset field. A lot of language std libs have adopted something along these lines.
DJB was advocating for everything to be in a format like this, referenced to TAI (UTC without leap seconds, basically). Sadly that didn't get any traction.
I was horrified even more when i learned that future leap seconds are undefined, and we literally can't tell what is the time on the clock lik3w a million seconds from now.
If you want to know what's broken? Most real time clock modules. They almost all want to store time as HH:MM:SS MM:DD:YY and sometimes 1/256 of a second but sometimes not.