diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec index f8fbde750c..caf449ba2f 100644 --- a/ext/bigdecimal/bigdecimal.gemspec +++ b/ext/bigdecimal/bigdecimal.gemspec @@ -35,6 +35,7 @@ Gem::Specification.new do |s| s.required_ruby_version = Gem::Requirement.new(">= 2.4.0") + s.add_development_dependency "fiddle" s.add_development_dependency "rake", ">= 12.3.3" s.add_development_dependency "rake-compiler", ">= 0.9" s.add_development_dependency "minitest", "< 5.0.0" diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index c2591dea25..55992348e0 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -6,6 +6,21 @@ require 'rbconfig/sizeof' class TestBigDecimal < Test::Unit::TestCase include TestBigDecimalBase + if defined? RbConfig::LIMITS + LIMITS = RbConfig::LIMITS + else + require 'fiddle' + LONG_MAX = (1 << (Fiddle::SIZEOF_LONG*8 - 1)) - 1 + LONG_MIN = [LONG_MAX + 1].pack("L!").unpack("l!")[0] + LIMITS = { + "FIXNUM_MIN" => LONG_MIN / 2, + "FIXNUM_MAX" => LONG_MAX / 2, + "INT64_MIN" => -9223372036854775808, + "INT64_MAX" => 9223372036854775807, + "UINT64_MAX" => 18446744073709551615, + }.freeze + end + ROUNDING_MODE_MAP = [ [ BigDecimal::ROUND_UP, :up], [ BigDecimal::ROUND_DOWN, :down], @@ -111,20 +126,15 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(BigDecimal((2**100).to_s), BigDecimal(2**100)) assert_equal(BigDecimal((-2**100).to_s), BigDecimal(-2**100)) - assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"].to_s), - BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"])) + assert_equal(BigDecimal(LIMITS["FIXNUM_MIN"].to_s), BigDecimal(LIMITS["FIXNUM_MIN"])) - assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"].to_s), - BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"])) + assert_equal(BigDecimal(LIMITS["FIXNUM_MAX"].to_s), BigDecimal(LIMITS["FIXNUM_MAX"])) - assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MIN"].to_s), - BigDecimal(RbConfig::LIMITS["INT64_MIN"])) + assert_equal(BigDecimal(LIMITS["INT64_MIN"].to_s), BigDecimal(LIMITS["INT64_MIN"])) - assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MAX"].to_s), - BigDecimal(RbConfig::LIMITS["INT64_MAX"])) + assert_equal(BigDecimal(LIMITS["INT64_MAX"].to_s), BigDecimal(LIMITS["INT64_MAX"])) - assert_equal(BigDecimal(RbConfig::LIMITS["UINT64_MAX"].to_s), - BigDecimal(RbConfig::LIMITS["UINT64_MAX"])) + assert_equal(BigDecimal(LIMITS["UINT64_MAX"].to_s), BigDecimal(LIMITS["UINT64_MAX"])) end def test_BigDecimal_with_rational