You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/25 17:52:41 UTC

[GitHub] [arrow] Johnnathanalmeida commented on a diff in pull request #12581: ARROW-15940: [Gandiva][C++] Add NEGATIVE function for decimal data type

Johnnathanalmeida commented on code in PR #12581:
URL: https://github.com/apache/arrow/pull/12581#discussion_r857882566


##########
cpp/src/gandiva/precompiled/arithmetic_ops_test.cc:
##########
@@ -80,6 +83,35 @@ TEST(TestArithmeticOps, TestMod) {
   EXPECT_FALSE(context.has_error());
 }
 
+TEST(TestArithmeticOps, TestNegativeDecimal) {
+  gandiva::ExecutionContext ctx;
+  int64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx);
+
+  int64_t out_high_bits = 0;
+  uint64_t out_low_bits = 0;
+
+  arrow::Decimal128 input_decimal("-10.5");
+  negative_decimal(ctx_ptr, input_decimal.high_bits(), input_decimal.low_bits(), 3, 1, 3,
+                   1, &out_high_bits, &out_low_bits);
+  arrow::Decimal128 output_decimal("10.5");
+  EXPECT_EQ(output_decimal.high_bits(), out_high_bits);
+  EXPECT_EQ(output_decimal.low_bits(), out_low_bits);
+
+  arrow::Decimal128 input_decimal2("10.5");
+  negative_decimal(ctx_ptr, input_decimal2.high_bits(), input_decimal2.low_bits(), 3, 1,
+                   3, 1, &out_high_bits, &out_low_bits);
+  arrow::Decimal128 output_decimal2("-10.5");
+  EXPECT_EQ(output_decimal2.high_bits(), out_high_bits);
+  EXPECT_EQ(output_decimal2.low_bits(), out_low_bits);
+
+  arrow::Decimal128 input_decimal3("-23049223942343.532412");
+  negative_decimal(ctx_ptr, input_decimal3.high_bits(), input_decimal3.low_bits(), 20, 6,
+                   20, 6, &out_high_bits, &out_low_bits);
+  arrow::Decimal128 output_decimal3("23049223942343.532412");
+  EXPECT_EQ(output_decimal3.high_bits(), out_high_bits);
+  EXPECT_EQ(output_decimal3.low_bits(), out_low_bits);
+}

Review Comment:
   The new unit tests were add.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org