Skip to content

Commit

Permalink
ARROW-2733: [GLib] Cast garrow_decimal128 to gint64
Browse files Browse the repository at this point in the history
Add garrow_decimal128_to_integer().

Author: yosuke shiro <[email protected]>

Closes #2157 from shiro615/cast-garrow-decimal128-to-gint64 and squashes the following commits:

94b703a [yosuke shiro] [GLib] Cast garrow_decimal128 to gint64
  • Loading branch information
shiro615 authored and kou committed Jun 23, 2018
1 parent df327f6 commit 6ef9888
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions c_glib/arrow-glib/decimal.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6ef9888

Please sign in to comment.