Bug #111387 select -1*a; Why isn't the result zero?
Submitted: 13 Jun 2023 7:57 Modified: 13 Jun 2023 12:31
Reporter: haizhen xue Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[13 Jun 2023 7:57] haizhen xue
Description:
select -1*a;  result is -0,Why isn't the result zero?

How to repeat:
mysql> select -'a';
+------+
| -'a' |
+------+
|   -0 |
+------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)

Suggested fix:
select -1*a;  result is -0,Why isn't the result zero?
[13 Jun 2023 8:51] haizhen xue
select -1*a;  expect result is 0;
[13 Jun 2023 12:31] MySQL Verification Team
Hi Mr. xue,

Thank you for your bug report.

However, this is not a bug.

If you have read our Ref. Manual, you would have known that applying an integer operation to a string will convert the string to the floating point value, which is 0.0 for a string, with a warning.

Since -0.0 or -0 is a valid result for the  floating point type, this is not a bug.