From ff3e585014f6388636fbc2a57800fadce3b99219 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 21 Nov 2013 12:37:46 +0000 Subject: * ext/bigdecimal/bigdecimal.c (BigDecimal_sqrt): Fix the precision of the result BigDecimal of sqrt. [Bug #5266] [ruby-dev:44450] * test/bigdecimal/test_bigdecimal.rb: add tests for the above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/bigdecimal/test_bigdecimal.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/bigdecimal') diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 91eeafcff5..78ecd8bd30 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -804,6 +804,20 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(1, BigDecimal.new("1").sqrt(1)) end + def test_sqrt_5266 + x = BigDecimal('2' + '0'*100) + assert_equal('0.14142135623730950488016887242096980785696718753769480731', + x.sqrt(56).to_s(56).split(' ')[0]) + assert_equal('0.1414213562373095048801688724209698078569671875376948073', + x.sqrt(55).to_s(55).split(' ')[0]) + + x = BigDecimal('2' + '0'*200) + assert_equal('0.14142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462', + x.sqrt(110).to_s(110).split(' ')[0]) + assert_equal('0.1414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735013846', + x.sqrt(109).to_s(109).split(' ')[0]) + end + def test_fix x = BigDecimal.new("1.1") assert_equal(1, x.fix) -- cgit v1.2.3