Author: Dieter Buerssner
Date: 09:48:02 12/05/02
Go up one level in this thread
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
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.