Hacker News new | ask | show | jobs
by oshiar53-0 1639 days ago
Is there something wrong in particular for using built-in fixed-point types for timestamps?

Yes, overflow/underflow issues and yada yada, but virtually every type can be mised in its own way.

3 comments

Nothing wrong with fixed point. It's only a problem because people end up hand-rolling their arithmetic (and botching it) instead of using library functions that do it right.
Fixedpoint is great, but floating point behave more like how people appear to expect timestamps to work. That said, I like so many others have written my own damned fixed point function for various reasons, and like everyone else I got it wrong several times on the way. If only there was a simple template class that could take care of it for you, but well, such a simple template class would really just be a basic numeric type anyways, so why not include it in the specification, ensuring that a high performance, extremely well tested variant was available everywhere form the start.

Imagine how many millions of hours of coder time could have been saved if the C specification included fixedpoint<20,12> (or however you wanna write it), and thus would have created a single standard implementation for all of them. Having not just basic arithmetics, but decent sin, cos, sqrt, atan2 etc, all parth of cmath. The difference now would be minor with soft float beeing ubiquitous, but back when it was faster... Damn.

Fixed point could work, and they are certainly better than ints, but floating point behaves more like people expect timestamps to work, and the specific fixed-point I need never seems to be available.
You could use arbitrary precision rational numbers.

Many languages support these in their standard libraries. (Eg Python does.)

They are a bit slow compared to ints or floats, but good for precision.