[MDEV-5807] Field of type FLOAT does not cast well to integer Created: 2014-03-09  Updated: 2022-09-08

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.3.12, 5.5.36, 10.0.9
Fix Version/s: 5.5

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This SQL script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DOUBLE, b FLOAT);
INSERT INTO t1 VALUES (1.1e30,1.2e30);
SELECT CAST(a AS SIGNED),CAST(b as SIGNED) FROM t1;
SHOW WARNINGS;

returns a wrong result for the FLOAT field:

+---------------------+----------------------+
| CAST(a AS SIGNED)   | CAST(b as SIGNED)    |
+---------------------+----------------------+
| 9223372036854775807 | -9223372036854775808 |
+---------------------+----------------------+
1 row in set, 1 warning (0.00 sec)

The expected result should be 9223372036854775807,
the same with the DOUBLE field.

Also, a warning is not generated for the FLOAT field.
It is generated for the DOUBLE field only:

+---------+------+---------------------------------------------+
| Level   | Code | Message                                     |
+---------+------+---------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '1.1e30' |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)

FLOAT should be fixed to generate warnings, like DOUBLE does.


Generated at Thu Feb 08 07:07:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.