2 ms·
Why would anyone want to store time in signed integer? Or in any signed numerical type?
by misja111 1y ago
Why would anyone want to store time in signed integer? Or in any signed numerical type?
- lorenzohess 1y agoSo that my Arch Linux box can still work when we get time travel.
- FlyingAvatar 1y agoI have wondered this as well and my best guess is so two times can be diffed without converting them to an signed type. With 64-bit especially, the extra bit isn't buying you anything useful.
- benmmurphy 1y agoYou can have an epoch and now you can measure times before the epoch. In terms of the range of values you can represent it transposes to just having the epoch further in the past and using an unsigned type. So signed/unsigned it should not really matter except maybe for particular languages things work better if the type is either signed or unsigned. For example if you try to calculate the difference between two times maybe its better if the time type is signed to match the result type which is signed as well (not that it solves the problems with overflow).
- LegionMammal978 1y agoSo that people can represent times that occurred before 1970? You could try adjusting the epoch to the estimated age of the universe, but then you run into calendar issues (proleptic Gregorian?), have huge constants in the common case (Julian Days are not fun to work with), and still end up with issues if the estimate is ever revised upward.
- bhaney 1y agoSome things happened before 1970
- toast0 1y agoBlasphemy! The world sprung into being on Jan 1, 1970 UTC as-is, and you can't convince me otherwise. :P
- jech 1y agoSo you can write "delta = t1 - t0".
- toast0 1y agoIt's useful to have signed intervals, but most integer type systems return a signed number when subtracting a signed int from a signed int. You kind of have to pick your poison; do you want a) reasonable signed behavior for small differences but inability to represent large differences, b) only able to represent non-negative differences, but with the full width of the type, c) like a, but also convincing your programming system to do a mixed signed subtraction ... like for ptrdiff_t.
- layer8 1y agoSo that calculating “80 years ago” doesn’t result in a future time.