Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: get_ms() bug

Author: Dann Corbit

Date: 15:23:02 05/13/04

Go up one level in this thread


On May 13, 2004 at 17:42:01, Eugene Nalimov wrote:

>On May 13, 2004 at 17:37:08, Anthony Cozzie wrote:
>
>>On May 13, 2004 at 16:11:34, Jeff GAZET wrote:
>>
>>>hi,
>>>
>>>All versions of my engine have got a bug since a few hours : you can't set a
>>>fixed depth :-(
>>>
>>>for those who are using something like this :
>>>
>>>int stop_time;
>>>stop_time=get_ms()+1000;
>>>
>>>this is buggy now, as get_ms()>2146589376
>>>and long is 2147483647
>>
>>Always use subtraction:
>>
>>if(get_ms() - start_time > search_time ) do something;
>
>According to the C/C++ standards for signed types compiler can rewrite your
>condition as
>    if(get_ms() > start_time + search_time ) do something;

If you use double for all the time storage, then the subtraction overflow will
only be problematic when the counter resets the number.

Of course, in Windows you should use something like:

	  SYSTEMTIME st = {0};
	  GetSystemTime(&st);

or
	  SYSTEMTIME st = {0};
	  GetLocalTime(&st);

to collect the time.

I poke the results into Moshier's Qfloat and so there are no worries about
overflows.



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.