You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/05/13 17:33:01 UTC
[arrow] branch master updated: ARROW-2576: [GLib] Add abs functions
for Decimal128
This is an automated email from the ASF dual-hosted git repository.
uwe 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 19af862 ARROW-2576: [GLib] Add abs functions for Decimal128
19af862 is described below
commit 19af8625daca479bfa32d1d733724d552efb04d6
Author: yosuke shiro <ys...@gmail.com>
AuthorDate: Sun May 13 19:32:54 2018 +0200
ARROW-2576: [GLib] Add abs functions for Decimal128
Add garrow_decimal128_abs().
Author: yosuke shiro <ys...@gmail.com>
Closes #2037 from shiro615/ARROW-2576-add-abs-functions and squashes the following commits:
c34a5de9 <yosuke shiro> Add abs functions test case
0b9a9d4f <yosuke shiro> Add abs functions
---
c_glib/arrow-glib/decimal.cpp | 17 +++++++++++++++++
c_glib/arrow-glib/decimal.h | 1 +
c_glib/test/test-decimal.rb | 7 +++++++
3 files changed, 25 insertions(+)
diff --git a/c_glib/arrow-glib/decimal.cpp b/c_glib/arrow-glib/decimal.cpp
index ca57677..d05049a 100644
--- a/c_glib/arrow-glib/decimal.cpp
+++ b/c_glib/arrow-glib/decimal.cpp
@@ -172,6 +172,23 @@ garrow_decimal128_to_string(GArrowDecimal128 *decimal)
return g_strndup(string.data(), string.size());
}
+/**
+ * garrow_decimal128_abs:
+ * @decimal: A #GArrowDecimal128.
+ *
+ * Returns: (transfer full): The absolute value of the decimal.
+ *
+ * Since: 0.10.0
+ */
+GArrowDecimal128 *
+garrow_decimal128_abs(GArrowDecimal128 *decimal)
+{
+ auto arrow_decimal = garrow_decimal128_get_raw(decimal);
+ auto arrow_sub_decimal =
+ std::make_shared<arrow::Decimal128>(arrow_decimal->Abs());
+ return garrow_decimal128_new_raw(&arrow_sub_decimal);
+}
+
G_END_DECLS
GArrowDecimal128 *
diff --git a/c_glib/arrow-glib/decimal.h b/c_glib/arrow-glib/decimal.h
index 81e171b..d0196e9 100644
--- a/c_glib/arrow-glib/decimal.h
+++ b/c_glib/arrow-glib/decimal.h
@@ -40,5 +40,6 @@ GArrowDecimal128 *garrow_decimal128_new_integer(const gint64 data);
gchar *garrow_decimal128_to_string_scale(GArrowDecimal128 *decimal,
gint32 scale);
gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal);
+GArrowDecimal128 *garrow_decimal128_abs(GArrowDecimal128 *decimal);
G_END_DECLS
diff --git a/c_glib/test/test-decimal.rb b/c_glib/test/test-decimal.rb
index 213d4f0..8e46fc5 100644
--- a/c_glib/test/test-decimal.rb
+++ b/c_glib/test/test-decimal.rb
@@ -28,4 +28,11 @@ class TestDecimal128 < Test::Unit::TestCase
decimal = Arrow::Decimal128.new(string_data)
assert_equal(string_data, decimal.to_s)
end
+
+ def test_abs
+ absolute_value = "23049223942343532412"
+ negative_value = "-23049223942343532412"
+ decimal = Arrow::Decimal128.new(negative_value)
+ assert_equal(absolute_value, decimal.abs.to_s)
+ end
end
--
To stop receiving notification emails like this one, please contact
uwe@apache.org.