Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Chigarev <[email protected]>
  • Loading branch information
dchigarev committed Jan 15, 2021
1 parent fac027e commit 021e641
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 5 additions & 2 deletions cpp/src/arrow/util/basic_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,11 @@ DecimalStatus BasicDecimalAnyWidth<width>::Divide(const BasicDecimalAnyWidth& di
bool dividen_was_negative = Sign() == -1;
bool divisor_was_negative = divisor.Sign() == -1;

*result = value / divisor.value;
*remainder = value % divisor.value;
BasicDecimalAnyWidth<width> dividen_abs = BasicDecimalAnyWidth<width>::Abs(*this);
BasicDecimalAnyWidth<width> divisor_abs = BasicDecimalAnyWidth<width>::Abs(divisor);

*result = dividen_abs.value / divisor_abs.value;
*remainder = dividen_abs.value % divisor_abs.value;

FixDivisionSigns(result, remainder, dividen_was_negative, divisor_was_negative);
return DecimalStatus::kSuccess;
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/util/basic_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ ARROW_EXPORT BasicDecimal256 operator/(const BasicDecimal256& left,
template <uint32_t width>
class ARROW_EXPORT BasicDecimalAnyWidth {
public:
static constexpr int bit_width = width;
using ValueType = typename IntTypes<width>::signed_type;
/// \brief Empty constructor creates a BasicDecimal with a value of 0.
constexpr BasicDecimalAnyWidth() noexcept : value(0) {}
Expand Down
14 changes: 7 additions & 7 deletions cpp/src/arrow/util/decimal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1729,20 +1729,20 @@ const std::vector<std::pair<std::string, std::function<T(T, T)>>>
TYPED_TEST(DecimalAnyWidthTest, BinaryOperations) {
using ValueType = typename arrow::DecimalAnyWidthTest_BinaryOperations_Test<
gtest_TypeParam_>::TypeParam::ValueType;
using ArrowValueType = typename arrow::CTypeTraits<ValueType>::ArrowType;

auto DecimalFns = DecimalAnyWidthBinaryParams<TypeParam>::value;
auto NumericFns = DecimalAnyWidthBinaryParams<int64_t>::value;

for (size_t i = 0; i < DecimalFns.size(); i++) {
for (auto x : GetRandomNumbers<ArrowValueType>(8)) {
for (auto y : GetRandomNumbers<ArrowValueType>(8)) {
for (ValueType x : GetRandomNumbers<Int32Type>(8)) {
for (ValueType y : GetRandomNumbers<Int32Type>(8)) {
TypeParam d1(x), d2(y);
auto result = DecimalFns[i].second(d1, d2);
auto reference = static_cast<ValueType>(NumericFns[i].second(x, y));
TypeParam result = DecimalFns[i].second(d1, d2);
ValueType reference = static_cast<ValueType>(NumericFns[i].second(x, y));
ASSERT_EQ(reference, result)
<< d1 << " " << DecimalFns[i].first << " " << d2 << " "
<< " != " << result;
<< "(" << x << " " << DecimalFns[i].first << " " << y << " = " << reference
<< ") != (" << d1 << " " << DecimalFns[i].first << " " << d2 << " = "
<< result << ")";
}
}
}
Expand Down

0 comments on commit 021e641

Please sign in to comment.