Author belopolsky
Recipients Arfrever, Niklas.Claesson, Ramchandra Apte, andrewclegg, belopolsky, goshawk, lemburg, pitrou, r.david.murray, tim.peters, vstinner
Date 2014-07-15.03:19:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1405394354.27.0.0782846331519.issue15443@psf.upfronthosting.co.za>
In-reply-to
Content
The following code demonstrates that we can pack year through second fields in 40 bits:

#include <stdio.h>
struct dt {
  unsigned year :14;   /* 1-9999 of 0-16,383 */
  unsigned month :4;   /* 1-12 of 0-16 */
  unsigned day   :5;   /* 1-31 of 0-31 */
  unsigned hour  :5;   /* 0-23 of 0-31 */
  unsigned minute:6;   /* 0-59 of 0-63 */
  unsigned second:6;   /* 0-59 of 0-63 */
  /* total :     40 bits */
};

int main() {
  struct dt t;
  t.year = 9999;
  t.month = 12;
  t.day = 31;
  t.hour = 24;
  t.minute = 59;
  t.second = 59;
  printf("%d-%d-%dT%d:%d:%d in %d bytes\n",
         t.year, t.month, t.day,
         t.hour, t.minute, t.second,
         (int)sizeof(t));
}

$ ./a.out
9999-12-31T24:59:59 in 8 bytes

Assuming 64-bit alignment, this leaves 64*2 - 40 = 88 bits for the sub-second field.

In 88 bits you can pack yoctoseconds (yocto = 1e-24) without breaking a sweat:

>>> 2**88
309485009821345068724781056
>>> 10**24
1000000000000000000000000

The practical choice is between 32-bit nanoseconds (nano = 1e-9) and 64-bit attoseconds (atto = 1e-18).

Given that the current the world record for shortest controllable time is 12 attoseconds [1], it may not be an absurd choice to go to 64 bits of sub-second precision.

On the other hand, if we manage to go from micro- to nano-seconds now, I don't think it will be hard to go to higher resolution when users start asking for it some 40 years into the future.


[1] http://phys.org/news192909576.html
History
Date User Action Args
2014-07-15 03:19:14belopolskysetrecipients: + belopolsky, lemburg, tim.peters, pitrou, vstinner, Arfrever, r.david.murray, andrewclegg, Ramchandra Apte, goshawk, Niklas.Claesson
2014-07-15 03:19:14belopolskysetmessageid: <1405394354.27.0.0782846331519.issue15443@psf.upfronthosting.co.za>
2014-07-15 03:19:14belopolskylinkissue15443 messages
2014-07-15 03:19:13belopolskycreate