Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-2733: [GLib] Cast garrow_decimal128 to gint64 #2157

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions c_glib/arrow-glib/decimal.cpp
Expand Up @@ -202,6 +202,21 @@ garrow_decimal128_negate(GArrowDecimal128 *decimal)
arrow_decimal->Negate();
}

/**
* garrow_decimal128_to_integer:
* @decimal: A #GArrowDecimal128.
*
* Returns: The 64-bit integer representation of the decimal.
*
* Since: 0.10.0
*/
gint64
garrow_decimal128_to_integer(GArrowDecimal128 *decimal)
{
auto arrow_decimal = garrow_decimal128_get_raw(decimal);
return static_cast<int64_t>(*arrow_decimal);
}

G_END_DECLS

GArrowDecimal128 *
Expand Down
1 change: 1 addition & 0 deletions c_glib/arrow-glib/decimal.h
Expand Up @@ -42,5 +42,6 @@ gchar *garrow_decimal128_to_string_scale(GArrowDecimal128 *decimal,
gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal);
void garrow_decimal128_abs(GArrowDecimal128 *decimal);
void garrow_decimal128_negate(GArrowDecimal128 *decimal);
gint64 garrow_decimal128_to_integer(GArrowDecimal128 *decimal);

G_END_DECLS
6 changes: 6 additions & 0 deletions c_glib/test/test-decimal.rb
Expand Up @@ -46,4 +46,10 @@ def test_negate
decimal.negate
assert_equal(positive_value, decimal.to_s)
end

def test_to_integer
integer_data = 999999999999999999
decimal = Arrow::Decimal128.new(integer_data)
assert_equal(integer_data, decimal.to_i)
end
end