Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > time_t, arithmetic types, difftime, and -

Reply
Thread Tools

time_t, arithmetic types, difftime, and -

 
 
Beej Jorgensen
Guest
Posts: n/a
 
      06-11-2009
That got me thinking:

time_t is an arithmetic type, and so the '-' operator will work on it.

But difftime() exists because there's nothing in the Standard that
specifies the encoding of a time_t variable, so this might BE true:

(t1 - t0) != difftime(t1, t0)

is this line of thinking correct?

Is this was the Rationale means when it says, "No arithmetic properties
of [clock_t and time_t] are defined by the Standard", that is, "When you
difftime() time 7 from time 10, you might not get time 3, even though
you will get 3 when you use the '-' operator."

-Beej

 
Reply With Quote
 
 
 
 
jameskuyper
Guest
Posts: n/a
 
      06-11-2009


Beej Jorgensen wrote:
> That got me thinking:
>
> time_t is an arithmetic type, and so the '-' operator will work on it.
>
> But difftime() exists because there's nothing in the Standard that
> specifies the encoding of a time_t variable, so this might BE true:
>
> (t1 - t0) != difftime(t1, t0)
>
> is this line of thinking correct?


Yes. For instance, the time_t value corresponding to
2009-06-11T21:11:02Z might be 20090611.211102; the value for
2009-06-11T21:10:59Z might be 20090611.211059. difftime(t1, t0) must
return 3.0, but t1-t0 would be 0.000043.

> Is this was the Rationale means when it says, "No arithmetic properties
> of [clock_t and time_t] are defined by the Standard", that is, "When you
> difftime() time 7 from time 10, you might not get time 3, even though
> you will get 3 when you use the '-' operator."


Yes. The manner in which time_t values are encoded is completely
unspecified by the standard. Emphasize the word "completely". Think
about it.
 
Reply With Quote
 
 
 
 
Fred
Guest
Posts: n/a
 
      06-11-2009
On Jun 11, 2:47*pm, jameskuyper <(E-Mail Removed)> wrote:
> Beej Jorgensen wrote:
> > That got me thinking:

>
> > time_t is an arithmetic type, and so the '-' operator will work on it.

>
> > But difftime() exists because there's nothing in the Standard that
> > specifies the encoding of a time_t variable, so this might BE true:

>
> > * (t1 - t0) != difftime(t1, t0)

>
> > is this line of thinking correct?

>
> Yes. For instance, the time_t value corresponding to
> 2009-06-11T21:11:02Z might be 20090611.211102; the value for
> 2009-06-11T21:10:59Z might be 20090611.211059. difftime(t1, t0) must
> return 3.0, but t1-t0 would be 0.000043.
>
> > Is this was the Rationale means when it says, "No arithmetic properties
> > of [clock_t and time_t] are defined by the Standard", that is, "When you
> > difftime() time 7 from time 10, you might not get time 3, even though
> > you will get 3 when you use the '-' operator."

>
> Yes. The manner in which time_t values are encoded is completely
> unspecified by the standard. Emphasize the word "completely". *Think
> about it.


Even if you know the encoding, you cannot rely on your own
subtractions to get the correct delta time.

A correct implementation of difftime must also know about all of
the leap-seconds that have been added between the two input times
in order to correctly determine the difference.

For example, the last three leap-seconda were added on:
Jun 30 1998,
Jan 31 2005, and
Jan 31 2008

It is possible that the leap-second will be abolished in the
future, which will cause UTC to begin drifting from solar time.

--
Fred Kleinschmidt
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-12-2009
Jack Klein wrote:
> On Thu, 11 Jun 2009 20:22:22 -0500, pete <(E-Mail Removed)>
> wrote in comp.lang.c:
>
>> Eric Sosman wrote:
>>>[...]
>>> Bits 0-5: Seconds (0-60)
>>> Bits 6-11: Minutes (0-59)
>>> Bits 12-16: Hours (0-23)
>>> Bits 17-21: Day of month (1-31)
>>> Bits 22-25: Month (1-12)
>>> Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
>>>[...]

> Assuming that we correct for Eric's use of 33 bits,


I *might* have made an off-by-one error, but isn't it
*far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
Yes, yes, *of course* that's the explanation ...

Trivia question: Why 1957 for Year Zero?

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      06-12-2009
On June 12, 2009 09:39, in comp.lang.c, Eric Sosman
((E-Mail Removed)) wrote:

> Jack Klein wrote:
>> On Thu, 11 Jun 2009 20:22:22 -0500, pete <(E-Mail Removed)>
>> wrote in comp.lang.c:
>>
>>> Eric Sosman wrote:
>>>>[...]

[snip]
>>>> Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
>>>>[...]

>> Assuming that we correct for Eric's use of 33 bits,

>
> I *might* have made an off-by-one error, but isn't it
> *far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
> Yes, yes, *of course* that's the explanation ...
>
> Trivia question: Why 1957 for Year Zero?
>


Guesses:
1) The year of the passing of John von Neumann,
2) The year of the founding of Digital Equipment Corporation, or
3) The year of the founding of the Advanced Projects Research Agency of
the US Department of Defense


--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


 
Reply With Quote
 
Beej Jorgensen
Guest
Posts: n/a
 
      06-12-2009
Lew Pitcher <(E-Mail Removed)> wrote:
>On June 12, 2009 09:39, in comp.lang.c, Eric Sosman
>> Trivia question: Why 1957 for Year Zero?

>
>Guesses:
> 1) The year of the passing of John von Neumann,
> 2) The year of the founding of Digital Equipment Corporation, or
> 3) The year of the founding of the Advanced Projects Research Agency of
> the US Department of Defense


No, no! It was the year the first Frisbee flying disc was produced!
Yes!

A legitimate guess: birth year of FORTRAN?

-Beej

 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      06-12-2009
On June 12, 2009 14:14, in comp.lang.c, Beej Jorgensen ((E-Mail Removed)) wrote:

> Lew Pitcher <(E-Mail Removed)> wrote:
>>On June 12, 2009 09:39, in comp.lang.c, Eric Sosman
>>> Trivia question: Why 1957 for Year Zero?

>>
>>Guesses:
>> 1) The year of the passing of John von Neumann,
>> 2) The year of the founding of Digital Equipment Corporation, or
>> 3) The year of the founding of the Advanced Projects Research Agency of
>> the US Department of Defense

>
> No, no! It was the year the first Frisbee flying disc was produced!
> Yes!
>
> A legitimate guess: birth year of FORTRAN?


And I counter with
the year that the first "recursive stack" (aka lifo) was implemented in a
computer language
or
the year that the Athena computer was completed
or
the year that the first all-solid-state computer (the NCR 304) was built

But, I think your FORTRAN guess is closer to the money

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-12-2009
Lew Pitcher wrote:
> On June 12, 2009 09:39, in comp.lang.c, Eric Sosman
> ((E-Mail Removed)) wrote:
>
>> Jack Klein wrote:
>>> On Thu, 11 Jun 2009 20:22:22 -0500, pete <(E-Mail Removed)>
>>> wrote in comp.lang.c:
>>>
>>>> Eric Sosman wrote:
>>>>> [...]

> [snip]
>>>>> Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
>>>>> [...]
>>> Assuming that we correct for Eric's use of 33 bits,

>> I *might* have made an off-by-one error, but isn't it
>> *far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
>> Yes, yes, *of course* that's the explanation ...
>>
>> Trivia question: Why 1957 for Year Zero?
>>

>
> Guesses:
> 1) The year of the passing of John von Neumann,
> 2) The year of the founding of Digital Equipment Corporation, or
> 3) The year of the founding of the Advanced Projects Research Agency of
> the US Department of Defense


As with all such, there are many candidates. (3) was
closest to the one I had in mind, because even though ARPA
was founded in 1958 rather than 1957, it was in reaction to
the 1957 event. Without the scare Sputnik gave the States,
and the concomitant flow of funding to fight off fear, we
might still be using 4MHz machines with half-megabyte memories.

There was a piece in The Register recently about the first
"portable computer:" No, not the Osborne or some such, but the
on-board navigational system of the Minuteman I, something of
a triumph of miniaturization at the time. According to the
article, the U.S. military was for a time the world's largest
purchaser of those newfangled integrated circuits, and the
principal reason for IC makers to go into and stay in business.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      06-13-2009
Beej Jorgensen <(E-Mail Removed)> wrote:

> Lew Pitcher <(E-Mail Removed)> wrote:
> >On June 12, 2009 09:39, in comp.lang.c, Eric Sosman
> >> Trivia question: Why 1957 for Year Zero?

> >
> >Guesses:
> > 1) The year of the passing of John von Neumann,
> > 2) The year of the founding of Digital Equipment Corporation, or
> > 3) The year of the founding of the Advanced Projects Research Agency of
> > the US Department of Defense

>
> No, no! It was the year the first Frisbee flying disc was produced!
> Yes!
>
> A legitimate guess: birth year of FORTRAN?


Birth year of a certain Mr. E. Sosman?

Richard
 
Reply With Quote
 
Steve Allen
Guest
Posts: n/a
 
      06-19-2009
On Jun 11, 3:12*pm, Fred <(E-Mail Removed)> wrote:
> A correct implementation of difftime must also know about all of
> theleap-secondsthat have been added between the two input times
> in order to correctly determine the difference.


a correct implementation of difftime must make a policy decision
of the sort that federal governments around the world have not
been able to make in a consistent fashion: to decide what kind of
seconds are supposed to be counted. See
http://www.ucolick.org/~sla/leapsecs/epochtime.html
for a javascript example of the issues.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A kind of arithmetic for subnetting and ip address management lily Cisco 0 05-08-2006 09:32 AM
A kind data structure and arithmetic for subnetting Hell Cisco 0 05-01-2006 02:36 AM
Simple library for arithmetic expression pasring and evaluating John Doe Java 0 04-17-2005 10:03 PM
Usual Arithmetic Conversions-arithmetic expressions joshc C Programming 5 03-31-2005 02:23 AM
Arithmetic conversions/promotion and templates =?ISO-8859-1?Q?Christian_Brechb=FChler?= C++ 3 10-20-2003 04:00 AM



Advertisments