Bug #78933 Negative zero(-0) is returned for mod(%) operation
Submitted: 23 Oct 2015 4:07 Modified: 4 Nov 2015 18:43
Reporter: Su Dylan Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.7.8, 5.7.9, 5.6.28, 5.5.47 OS:Any
Assigned to: CPU Architecture:Any

[23 Oct 2015 4:07] Su Dylan
Description:
Output:
=======
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t1 (c1 double);
insert Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1(c1) values (-1), (1);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select c1%c1 from t1;
+-------+
| c1%c1 |
+-------+
|    -0 |
|     0 |
+-------+
2 rows in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

Problem:
========
0 is expected here, not -0.

How to repeat:

drop table if exists t1;
create table t1 (c1 double);
insert into t1(c1) values (-1), (1);
select c1%c1 from t1;

Suggested fix:
0 is expected here, not -0.
[23 Oct 2015 7:43] MySQL Verification Team
Hello Su Dylan,

Thank you for the report.

Thanks,
Umesh
[27 Oct 2015 13:02] Tor Didriksen
Posted by developer:
 
The result modulo for negative numbers is implementation defined.
MySQL uses fmod(3) from the C library, which returns negative zero for this case.
So I would say this is "not a bug"
[4 Nov 2015 18:43] Erlend Dahl
Posted by developer:

27 Oct 2015 6:02] Tor Didriksen 

The result modulo for negative numbers is implementation defined.
MySQL uses fmod(3) from the C library, which returns negative zero for this
case.
So I would say this is "not a bug"