[MDEV-30592] Negative numbers are shifted left or right by 0 digits. The calculation result is incorrect. Created: 2023-02-07  Updated: 2023-02-08  Resolved: 2023-02-08

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.5.16, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Zeng Assignee: Alexander Barkov
Resolution: Not a Bug Votes: 0
Labels: upstream


 Description   

We get the incorrect result when we let the negative numbers shift left or right by 0 digits.
 
mysql> SELECT -1 >> 0;
+----------------------+
| -1 >> 0              |
+----------------------+
| 18446744073709551615 |
+----------------------+
1 row in set (0.00 sec)
 
mysql> SELECT -1 << 0;
+----------------------+
| -1 << 0              |
+----------------------+
| 18446744073709551615 |
+----------------------+
1 row in set (0.00 sec)

The result is incorrect. It should be -1.



 Comments   
Comment by Alexander Barkov [ 2023-02-08 ]

According to:

https://mariadb.com/kb/en/bit-functions-and-operators/

Operators for comparison and setting of values, and related functions. They all return a result of the BIGINT UNSIGNED type

Thus these operations cannot return -1.

Generated at Thu Feb 08 10:17:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.