This is an automated email from the ASF dual-hosted git repository. ravindra pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push: new 1f49604 ARROW-4653: [C++] Fix bug in decimal multiply 1f49604 is described below commit 1f49604498dd20e224c996135ea8c57ac38f426e Author: Pindikura Ravindra <ravin...@dremio.com> AuthorDate: Fri Feb 22 12:16:30 2019 +0530 ARROW-4653: [C++] Fix bug in decimal multiply - fixed a bug which was causing multiply to return an incorrect value when both args are -ve. Author: Pindikura Ravindra <ravin...@dremio.com> Closes #3728 from pravindra/multbug and squashes the following commits: 7a7b0c2e <Pindikura Ravindra> ARROW-4653: Fix bug in decimal multiply --- cpp/src/arrow/util/basic_decimal.cc | 2 +- cpp/src/arrow/util/decimal-test.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/util/basic_decimal.cc b/cpp/src/arrow/util/basic_decimal.cc index bb235f4..f8d3a72 100644 --- a/cpp/src/arrow/util/basic_decimal.cc +++ b/cpp/src/arrow/util/basic_decimal.cc @@ -243,13 +243,13 @@ BasicDecimal128& BasicDecimal128::operator*=(const BasicDecimal128& right) { product = L2 * R3; sum += product; + high_bits_ = static_cast<int64_t>(sum < product ? kCarryBit : 0); product = L3 * R2; sum += product; low_bits_ += sum << 32; - high_bits_ = static_cast<int64_t>(sum < product ? kCarryBit : 0); if (sum < product) { high_bits_ += kCarryBit; } diff --git a/cpp/src/arrow/util/decimal-test.cc b/cpp/src/arrow/util/decimal-test.cc index 032e02b..3d6e23d 100644 --- a/cpp/src/arrow/util/decimal-test.cc +++ b/cpp/src/arrow/util/decimal-test.cc @@ -466,6 +466,22 @@ TEST(Decimal128Test, TestToInteger) { ASSERT_RAISES(Invalid, invalid_int64.ToInteger(&out2)); } +TEST(Decimal128Test, Multiply) { + Decimal128 result; + + result = Decimal128("301") * Decimal128("201"); + ASSERT_EQ(result.ToIntegerString(), "60501"); + + result = Decimal128("-301") * Decimal128("201"); + ASSERT_EQ(result.ToIntegerString(), "-60501"); + + result = Decimal128("301") * Decimal128("-201"); + ASSERT_EQ(result.ToIntegerString(), "-60501"); + + result = Decimal128("-301") * Decimal128("-201"); + ASSERT_EQ(result.ToIntegerString(), "60501"); +} + TEST(Decimal128Test, GetWholeAndFraction) { Decimal128 value("123456"); Decimal128 whole;