home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,809 of 243,242   
   Keith Thompson to Michael S   
   Re: printf and time_t   
   05 Jan 26 15:04:22   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   Michael S  writes:   
   > On Mon, 5 Jan 2026 16:23:09 -0000 (UTC)   
   > Lew Pitcher  wrote:   
   [...]   
   >> As Andrey pointed out, time_t can resolve to a floatingpoint type,   
   >> so, "long long" would go wrong if the implementation typedefs it to   
   >>  float, or   
   >>  double, or   
   >>  long double.   
   >   
   > Reading literally what you wrote makes no sense, so I assume that you   
   > meant that 'it' above constitutes time_t rather than 'long long'.   
   >   
   > The rest of the post assumes 64-bit 'long long'.   
   > 'typedef float time_t' where float==IEEE binary32 is a bad idea, because   
   > you lose your 1sec resolution after 7 months. I.e. with Unix epoch you   
   > lost it a year or two before Ritchi finished his first C compiler.   
   > 'typedef double time_t' means that you lost 1 sec resolution ~3   
   > orders of magnitude before you got a chance to overflow 'long long'.   
   >   
   > Only in case of 'typedef long double time_t' there is a chance that   
   > overflow happens before resolution is lost. But barely so for 80-bit   
   > long double format prevalent on i386/AMD64 computers.   
      
   Assuming IEEE floating-point, and assuming time_t represents seconds   
   since the usual 1970 epoch, the current resolution of a 64-bit   
   floating-point time_t would be about 238 nanoseconds.  It has   
   that same resolution for any time from 2004-01-10 to 2038-01-18.   
   (The resolution doubles when the number of seconds since 1970   
   exceeds a power of 2.)  The resolution doesn't reach one second   
   until 142715360-12-05 (that's a Friday if we're still using the   
   same calendar).   
      
   I don't suggest that using type double for time_t would be a good   
   idea, and in fact POSIX requires time_t to be an integer type.   
   (I think Windows does as well, but the documentation is less clear,   
   or perhaps I'm missing something.)   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the void */   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca