Skip to content

Commit 6ca246a

Browse files
shiro615kou
authored andcommitted
ARROW-2582: [GLib] Add negate functions for Decimal128
Add garrow_decimal128_negate(). Author: yosuke shiro <[email protected]> Closes #2047 from shiro615/ARROW-2576-add-negate-functions and squashes the following commits: 7a63d00 [yosuke shiro] rename absolute_value to positive_value 815f449 [yosuke shiro] Add negate functions
1 parent 38db8ed commit 6ca246a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

c_glib/arrow-glib/decimal.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,21 @@ garrow_decimal128_abs(GArrowDecimal128 *decimal)
187187
arrow_decimal->Abs();
188188
}
189189

190+
/**
191+
* garrow_decimal128_negate:
192+
* @decimal: A #GArrowDecimal128.
193+
*
194+
* Negate the current value of the @decimal destructively.
195+
*
196+
* Since: 0.10.0
197+
*/
198+
void
199+
garrow_decimal128_negate(GArrowDecimal128 *decimal)
200+
{
201+
auto arrow_decimal = garrow_decimal128_get_raw(decimal);
202+
arrow_decimal->Negate();
203+
}
204+
190205
G_END_DECLS
191206

192207
GArrowDecimal128 *

c_glib/arrow-glib/decimal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ gchar *garrow_decimal128_to_string_scale(GArrowDecimal128 *decimal,
4141
gint32 scale);
4242
gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal);
4343
void garrow_decimal128_abs(GArrowDecimal128 *decimal);
44+
void garrow_decimal128_negate(GArrowDecimal128 *decimal);
4445

4546
G_END_DECLS

c_glib/test/test-decimal.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ def test_abs
3636
decimal.abs
3737
assert_equal(absolute_value, decimal.to_s)
3838
end
39+
40+
def test_negate
41+
positive_value = "23049223942343532412"
42+
negative_value = "-23049223942343532412"
43+
decimal = Arrow::Decimal128.new(positive_value)
44+
decimal.negate
45+
assert_equal(negative_value, decimal.to_s)
46+
decimal.negate
47+
assert_equal(positive_value, decimal.to_s)
48+
end
3949
end

0 commit comments

Comments
 (0)