From df33325192b6f09828ccdbe537397cd38679e979 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 12 Dec 2013 17:02:27 +0000 Subject: * ext/bigdecimal/bigdecimal.c (VpSetPTR): fix for limitation of the resulting precision. * test/bigdecimal/test_bigdecimal.rb (test_limit): add tests for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44153 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/bigdecimal/test_bigdecimal.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/bigdecimal/test_bigdecimal.rb') diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index e7bb1c513d..6fdc422fdf 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1151,6 +1151,25 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(90, x ** 4) # OK? must it be 80? # 3 * 3 * 3 * 3 = 10 * 3 * 3 = 30 * 3 = 90 ??? assert_raise(ArgumentError) { BigDecimal.limit(-1) } + + bug7458 = '[ruby-core:50269] [#7458]' + one = BigDecimal('1') + epsilon = BigDecimal('0.7E-18') + BigDecimal.save_limit do + BigDecimal.limit(0) + assert_equal(BigDecimal("1.0000000000000000007"), one + epsilon, "limit(0) #{bug7458}") + + 1.upto(18) do |lim| + BigDecimal.limit(lim) + assert_equal(BigDecimal("1.0"), one + epsilon, "limit(#{lim}) #{bug7458}") + end + + BigDecimal.limit(19) + assert_equal(BigDecimal("1.000000000000000001"), one + epsilon, "limit(19) #{bug7458}") + + BigDecimal.limit(20) + assert_equal(BigDecimal("1.0000000000000000007"), one + epsilon, "limit(20) #{bug7458}") + end end def test_sign -- cgit v1.2.3