Skip to content

Commit

Permalink
[ISSUE-1225] Fix the bug of += decimal in olap engine
Browse files Browse the repository at this point in the history
This change fix the olap engine bug of decimal agg. Using ^ instead of * to judge result is less then zero.
The result of * will be less then zero when the result is overflow. So the answer of += is incorrect.
  • Loading branch information
EmmyMiao87 committed May 30, 2019
1 parent fa4ac9f commit 0b7eb19
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion be/src/olap/field_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ inline std::ostream& operator<<(std::ostream& os, const uint24_t& val) {
return os;
}

// the sign of integer must be same as fraction
struct decimal12_t {
decimal12_t() : integer(0), fraction(0) {}
decimal12_t(int64_t int_part, int32_t frac_part) {
Expand All @@ -147,7 +148,8 @@ struct decimal12_t {
fraction += FRAC_RATIO;
}

if (fraction * integer < 0) {
// if sign of fraction is different from integer
if ((fraction ^ integer) < 0) {
bool sign = integer < 0;
integer += (sign ? 1 : -1);
fraction += (sign ? -FRAC_RATIO : FRAC_RATIO);
Expand Down

0 comments on commit 0b7eb19

Please sign in to comment.