Skip to content

Commit 3327f7b

Browse files
author
Tor Didriksen
committed
Bug#18411494 WRONG COMPARSION ON BIG DECIMAL VALUES
Post-push fix: Avoid negative zero when converting from float to decimal.
1 parent 0c58c93 commit 3327f7b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

mysql-test/r/type_newdecimal.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,6 @@ SELECT * FROM t1 WHERE value = '100000000000000000000002';
21302130
value
21312131
100000000000000000000002
21322132
DROP TABLE t1;
2133+
SELECT CAST(-0.0e0 AS DECIMAL) = 0;
2134+
CAST(-0.0e0 AS DECIMAL) = 0
2135+
1

mysql-test/t/type_newdecimal.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,3 +1711,5 @@ DEALLOCATE PREPARE stmt;
17111711
ALTER TABLE t1 ADD INDEX value (value);
17121712
SELECT * FROM t1 WHERE value = '100000000000000000000002';
17131713
DROP TABLE t1;
1714+
1715+
SELECT CAST(-0.0e0 AS DECIMAL) = 0;

sql/my_decimal.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ int str2my_decimal(uint mask, const char *from, size_t length,
267267
}
268268
}
269269
check_result_and_overflow(mask, err, decimal_value);
270-
// Avoid returning negative zero, cfr. decimal_cmp()
271-
if (decimal_value->sign() && decimal_is_zero(decimal_value))
272-
decimal_value->sign(false);
273270
return err;
274271
}
275272

strings/decimal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,9 @@ internal_str2dec(const char *from, decimal_t *to, char **end, my_bool fixed)
996996
error= decimal_shift(to, (int) exponent);
997997
}
998998
}
999+
/* Avoid returning negative zero, cfr. decimal_cmp() */
1000+
if (to->sign && decimal_is_zero(to))
1001+
to->sign= FALSE;
9991002
return error;
10001003

10011004
fatal_error:

0 commit comments

Comments
 (0)