mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
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.
This commit is contained in:
parent
8460db12b5
commit
29851b677e
4 changed files with 44 additions and 4 deletions
|
@ -672,5 +672,26 @@ Warnings:
|
|||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010e0)
|
||||
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
|
||||
#
|
||||
|
|
|
@ -1892,9 +1892,13 @@ Warnings:
|
|||
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);
|
||||
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
|
||||
INSERT INTO t5 VALUES('1e+53','-1e+53','1e+53',7),('1e-53','-1e-53','1e-53',8);
|
||||
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
|
||||
SELECT * FROM t5;
|
||||
c1 c2 c3 c4
|
||||
|
|
|
@ -485,6 +485,20 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0;
|
|||
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 # End of 10.1 tests
|
||||
--echo #
|
||||
|
|
|
@ -4627,11 +4627,12 @@ int truncate_double(double *nr, uint field_length, uint dec,
|
|||
{
|
||||
uint order= field_length - dec;
|
||||
uint step= array_elements(log_10) - 1;
|
||||
max_value= 1.0;
|
||||
double max_value_by_dec= 1.0;
|
||||
for (; order > step; order-= step)
|
||||
max_value*= log_10[step];
|
||||
max_value*= log_10[order];
|
||||
max_value-= 1.0 / log_10[dec];
|
||||
max_value_by_dec*= log_10[step];
|
||||
max_value_by_dec*= log_10[order];
|
||||
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 */
|
||||
if (!my_isinf(res))
|
||||
|
|
Loading…
Add table
Reference in a new issue