Skip to content

Commit

Permalink
Bug#18411494 WRONG COMPARSION ON BIG DECIMAL VALUES
Browse files Browse the repository at this point in the history
Post-push fix: Avoid negative zero when converting from float to decimal.
  • Loading branch information
Tor Didriksen committed May 22, 2015
1 parent 0c58c93 commit 3327f7b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mysql-test/r/type_newdecimal.result
Original file line number Diff line number Diff line change
Expand Up @@ -2130,3 +2130,6 @@ SELECT * FROM t1 WHERE value = '100000000000000000000002';
value
100000000000000000000002
DROP TABLE t1;
SELECT CAST(-0.0e0 AS DECIMAL) = 0;
CAST(-0.0e0 AS DECIMAL) = 0
1
2 changes: 2 additions & 0 deletions mysql-test/t/type_newdecimal.test
Original file line number Diff line number Diff line change
Expand Up @@ -1711,3 +1711,5 @@ DEALLOCATE PREPARE stmt;
ALTER TABLE t1 ADD INDEX value (value);
SELECT * FROM t1 WHERE value = '100000000000000000000002';
DROP TABLE t1;

SELECT CAST(-0.0e0 AS DECIMAL) = 0;
3 changes: 0 additions & 3 deletions sql/my_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ int str2my_decimal(uint mask, const char *from, size_t length,
}
}
check_result_and_overflow(mask, err, decimal_value);
// Avoid returning negative zero, cfr. decimal_cmp()
if (decimal_value->sign() && decimal_is_zero(decimal_value))
decimal_value->sign(false);
return err;
}

Expand Down
3 changes: 3 additions & 0 deletions strings/decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,9 @@ internal_str2dec(const char *from, decimal_t *to, char **end, my_bool fixed)
error= decimal_shift(to, (int) exponent);
}
}
/* Avoid returning negative zero, cfr. decimal_cmp() */
if (to->sign && decimal_is_zero(to))
to->sign= FALSE;
return error;

fatal_error:
Expand Down

0 comments on commit 3327f7b

Please sign in to comment.