summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 12:37:46 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 12:37:46 +0000
commitff3e585014f6388636fbc2a57800fadce3b99219 (patch)
treed1a130d04121e11d11d9e4663db557f5c20a3bba /test
parentd1d737ae5751f07a55c80a6761fa4f126e7d6f1f (diff)
* 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
Diffstat (limited to 'test')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 91eeafcff52..78ecd8bd300 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)