Bug #34090 Wrong result when computing unsigned
Submitted: 27 Jan 2008 13:35 Modified: 28 Jan 2008 5:28
Reporter: Florent Palomares Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:MySQL - 5.0.22 OS:Microsoft Windows (XP)
Assigned to: CPU Architecture:Any

[27 Jan 2008 13:35] Florent Palomares
Description:
Hi,

I have a weird  behavior when computing unsigned int,
the result seems to be considered as unsigned too...
so, if the expected value was negative, the given value
is a positive number!

Regards,
Florent

How to repeat:
CREATE TABLE test (
  `a` tinyint(3) unsigned NOT NULL,
  `b` tinyint(3) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO test VALUES (1, 2);

SELECT * , 2 * a -2 * b FROM test

=> I have :
 a  	 b  	 2 * a - 2 * b
1 	2 	18446744073709551614
[28 Jan 2008 5:28] Valeriy Kravchuk
Sorry, but formally this is not a bug. Read http://dev.mysql.com/doc/refman/5.0/en/arithmetic-functions.html:

"If one of the arguments is an unsigned integer, and the other argument is also an integer, the result is an unsigned integer."