Commit 29851b67 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-23282 FLOAT(53,0) badly handles out-of-range values

truncate_double() did not take into account the max_value
limit in case when dec<NOT_FIXED_DEC.
parent 8460db12
...@@ -672,5 +672,26 @@ Warnings: ...@@ -672,5 +672,26 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010e0) Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010e0)
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-23282 FLOAT(53,0) badly handles out-of-range values
#
CREATE OR REPLACE TABLE t1 (c1 FLOAT NOT NULL, c2 FLOAT NOT NULL);
INSERT IGNORE INTO t1 VALUES (1e+40, -1e+40);
Warnings:
Warning 1264 Out of range value for column 'c1' at row 1
Warning 1264 Out of range value for column 'c2' at row 1
SELECT c1, c2 FROM t1;
c1 c2
3.40282e38 -3.40282e38
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (c1 FLOAT(53,0) NOT NULL, c2 FLOAT(53,0) NOT NULL);
INSERT IGNORE INTO t1 VALUES (1e+40, -1e+40);
Warnings:
Warning 1264 Out of range value for column 'c1' at row 1
Warning 1264 Out of range value for column 'c2' at row 1
SELECT c1, c2 FROM t1;
c1 c2
340282346638528860000000000000000000000 -340282346638528860000000000000000000000
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -1892,9 +1892,13 @@ Warnings: ...@@ -1892,9 +1892,13 @@ Warnings:
Warning 1264 Out of range value for column 'c1' at row 3 Warning 1264 Out of range value for column 'c1' at row 3
INSERT INTO t5 VALUES('1e+52','-1e+52','1e+52',5),('1e-52','-1e-52','1e-52',6); INSERT INTO t5 VALUES('1e+52','-1e+52','1e+52',5),('1e-52','-1e-52','1e-52',6);
Warnings: Warnings:
Warning 1264 Out of range value for column 'c1' at row 1
Warning 1264 Out of range value for column 'c2' at row 1
Warning 1264 Out of range value for column 'c3' at row 1 Warning 1264 Out of range value for column 'c3' at row 1
INSERT INTO t5 VALUES('1e+53','-1e+53','1e+53',7),('1e-53','-1e-53','1e-53',8); INSERT INTO t5 VALUES('1e+53','-1e+53','1e+53',7),('1e-53','-1e-53','1e-53',8);
Warnings: Warnings:
Warning 1264 Out of range value for column 'c1' at row 1
Warning 1264 Out of range value for column 'c2' at row 1
Warning 1264 Out of range value for column 'c3' at row 1 Warning 1264 Out of range value for column 'c3' at row 1
SELECT * FROM t5; SELECT * FROM t5;
c1 c2 c3 c4 c1 c2 c3 c4
......
...@@ -485,6 +485,20 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0; ...@@ -485,6 +485,20 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-23282 FLOAT(53,0) badly handles out-of-range values
--echo #
CREATE OR REPLACE TABLE t1 (c1 FLOAT NOT NULL, c2 FLOAT NOT NULL);
INSERT IGNORE INTO t1 VALUES (1e+40, -1e+40);
SELECT c1, c2 FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (c1 FLOAT(53,0) NOT NULL, c2 FLOAT(53,0) NOT NULL);
INSERT IGNORE INTO t1 VALUES (1e+40, -1e+40);
SELECT c1, c2 FROM t1;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -4627,11 +4627,12 @@ int truncate_double(double *nr, uint field_length, uint dec, ...@@ -4627,11 +4627,12 @@ int truncate_double(double *nr, uint field_length, uint dec,
{ {
uint order= field_length - dec; uint order= field_length - dec;
uint step= array_elements(log_10) - 1; uint step= array_elements(log_10) - 1;
max_value= 1.0; double max_value_by_dec= 1.0;
for (; order > step; order-= step) for (; order > step; order-= step)
max_value*= log_10[step]; max_value_by_dec*= log_10[step];
max_value*= log_10[order]; max_value_by_dec*= log_10[order];
max_value-= 1.0 / log_10[dec]; max_value_by_dec-= 1.0 / log_10[dec];
set_if_smaller(max_value, max_value_by_dec);
/* Check for infinity so we don't get NaN in calculations */ /* Check for infinity so we don't get NaN in calculations */
if (!my_isinf(res)) if (!my_isinf(res))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment