Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: BitScan with reset - not so impressive with 3DNow!

Author: Matt Taylor

Date: 12:39:40 12/05/02

Go up one level in this thread


On December 05, 2002 at 12:48:02, Dieter Buerssner wrote:

>On December 05, 2002 at 11:25:27, Gerd Isenberg wrote:
>
>>Most (All?) C-compilers have no problem with unary minus and constants:
>>
>>unsigned int A = -CONST;
>
>Assume 32 bit integers, and const is -2^31.
>I believe, the above is undefined behaviour. In this case a cast will make it
>defined behaviour:
>
>  unsigned int A = -(unsigned)CONST.
>
>Totally unrelated to chess. If you want to write a function to convert int to
>ASCII (without using sprintf) the typical way may be:
>
>  int toconvert;
>  unsigned uval;
>  if (toconvert < 0)
>    uval = -toconvert; /* Oops, may not work for toconvert = INT_MIN */
>  /* and go on to convert the unsigned value */
>
>>Because -CONST is a kind synonym for the compiler which means implicitly
>>  (2**wordLengthInBits) - CONST ==> 0 - CONST
>
>All unsigned arithmetics is guaranteed to yield results mod 2 ^ bits.
>
>Cheers,
>Dieter

unsigned int A = -(-2^31)

A would be 2^31, regardless of signedness or unsignedness. The two's compliment
of -2^31 (80000000h) is 2^31 (7FFFFFFFh + 1).

My compiler gripes, but it lets me assign negative numbers to unsigned integers
regardless of whether it's at compile time with constants or runtime with
variables. (That happens to be quite useful when you want a mask with all bits
set -- just use -1.)

-Matt



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.