This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Stupid off-topic question


Maybe this will help you understand why gcc is correct.

main()
{
   signed   int x;
   unsigned int y;
   unsigned int z;

   x=-1;
   y=x;
   z=y%4083;
   printf("%u\n",y);
   printf("%u\n",z);
   printf("%u\n",4083*(y/4083)+z);
}

Output:

4294967295
2433
4294967295

-----Original Message-----
From: nbecker@fred.net [mailto:nbecker@fred.net]
Sent: Wednesday, August 02, 2000 2:00 PM
To: gcc@gcc.gnu.org
Subject: Stupid off-topic question


I can't understand this logic.

-1 % 4083 -> -1

But

 -1 % (unsigned)4083 -> 2433.

I would expect by any reasonable mathematical definition, that 

-1 % 4083 -> 4082.

This was gcc-2.95.2 i686-pc-linux-gnu.

If the generated code is really that stupid, maybe gcc should give a
warning?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]