summaryrefslogtreecommitdiff
path: root/test/bigdecimal/test_bigdecimal.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-11-09 12:56:45 +0100
committerKenta Murata <mrkn@mrkn.jp>2021-12-24 02:28:51 +0900
commitec478d947f218e1b94856941135701fe37e88fbc (patch)
tree06df0936316a025728ffe2715f4d03e021bf588f /test/bigdecimal/test_bigdecimal.rb
parentc539cfd235b46dfb831fe94b55b547c7ac4a58f6 (diff)
[ruby/bigdecimal] Fix negative Bignum conversion
Introduced in https://github.com/ruby/bigdecimal/commit/4792a917d806 `rb_absint_size` return the number of bytes needed to fit the absolute integer, but negative integers need the sign, so one more bit, and potentially one more byte. https://github.com/ruby/bigdecimal/commit/0f3d5d0eb7
Diffstat (limited to 'test/bigdecimal/test_bigdecimal.rb')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index e860c9d153..8d4d2353e3 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -2089,6 +2089,16 @@ class TestBigDecimal < Test::Unit::TestCase
assert_raise(err) { bd.send(:initialize_dup, bd2) }
end
+ def test_llong_min
+ # https://github.com/ruby/bigdecimal/issues/199
+ # Between LLONG_MIN and -ULLONG_MAX
+ llong_min = -(2 ** 63 + 1)
+ assert_equal BigDecimal(llong_min.to_s), BigDecimal(llong_min)
+
+ minus_ullong_max = -(2 ** 64 - 1)
+ assert_equal BigDecimal(minus_ullong_max.to_s), BigDecimal(minus_ullong_max)
+ end
+
def assert_no_memory_leak(code, *rest, **opt)
code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}"
super(["-rbigdecimal"],