Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Problem in manipulating time in mins & secs !

Author: David Mitchell

Date: 02:15:14 07/22/04

Go up one level in this thread


On July 21, 2004 at 10:42:23, Gopikrishna wrote:

>On July 21, 2004 at 07:47:25, Geoffrey Westwood wrote:
>
>>Hi
>>
>>Off the top of my head without testing code needs to look something like
>>
>>double timeInMillisecs
>>int timeInMins
>>double timeInSecs
>>
>>
>>timeInMillisecs = 62230;  /*  test 62.23 secs */
>>
>>timeInMins =  (int)(timeInMillisecs/60000);
>>
>>timeInSecs = (timeInMillisecs/60000 - (double)timeInMins) * 60;
>>
>>Printf("Total time:%d min:%2.2f secs", timeInMins, timeInSecs);
>>
>>it would be quite slow though due to the nasty casts
>>
>>  Regards Geoff
>>
>>
>>On July 21, 2004 at 03:45:39, Gopikrishna wrote:
>>
>>>Time is passed as double.I preffered double instead of unsigned long because for
>>>outputting fraction of secs like 2.23 secs, double is more convenient.
>>>
>>>  So ttm is passsed as double.
>>> if ((ttm/1000) >=60)
>>>{
>>>	ttm=ttm/1000;
>>>             ms=ttm/60;
>>>	ttm=(ttm-(ms1*60));
>>>	min1=(int)ms1;
>>>}
>>>else
>>>ttm=ttm/1000;
>>>
>>>In the above ms is declared as double whereas min1 as int.
>>>So when I print time as,
>>>Printf("Total time:%d min:%2.2f secs",min1,ttm);
>>>
>>>  So when time was passed as 61000 (or 61secs), its outputting as
>>>Total time:0 min:-61.00 sec
>>>Strange!!! Also another problem is its in minus.
>>>It should have been 1 min:1 sec.So am i doing anything wrong in the above?
>>>Actually I could have passed time as unsigned long instead of double but as you
>>>can see I want that secs to be accurate like 2.23 secs instead of 2 secs !
>>>  So please help me.Thanks.
>
>What Geoffrey said is working ! But the only thing is its outputting in minus
>but if I negate that its perfect! Thanks Geoffrey.

But it's not right, yet. In this line of code:

>>timeInMins =  (int)(timeInMillisecs/60000);

timeInMillisecs is a double, and you're equation has 60,000 for a divisor.
What's the precedence for the cast to int? When 61,000/60,000 == a negative
number, I'm sure it's "rolled" over.

Dave




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.