diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 15:33:42 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 15:33:42 +0000 |
commit | 678b6820f70d6bd09d6e5179755311f0774db22a (patch) | |
tree | 8f0046c73f7bfef401bc285dab97ad83c25e2b4f /test/bigdecimal | |
parent | 8f9ff461cf1f8d7e8031f9f5b7755bf154655d74 (diff) | |
download | ruby-678b6820f70d6bd09d6e5179755311f0774db22a.tar.gz |
* ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): support instantiation from
a Float through Rational.
* ext/bigdecimal/bigdecimal.c (BigDecimal_new): ditto.
* test/bigdecimal/test_bigdecimal.rb (test_global_new_float): add a test for
the above changes.
* test/bigdecimal/test_bigdecimal.rb (test_new_with_float): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 63873d2b7c..c0c5ea44a0 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -42,6 +42,14 @@ class TestBigDecimal < Test::Unit::TestCase assert_raise(ArgumentError) { BigDecimal(1.quo(3)) } end + def test_global_new_with_float + assert_equal(BigDecimal("0.1235"), BigDecimal(0.1234567, 4)) + assert_equal(BigDecimal("-0.1235"), BigDecimal(-0.1234567, 4)) + assert_raise(ArgumentError) { BigDecimal(0.1) } + assert_raise(ArgumentError) { BigDecimal(0.1, Float::DIG + 2) } + assert_nothing_raised { BigDecimal(0.1, Float::DIG + 1) } + end + def test_new assert_equal(1, BigDecimal.new("1")) assert_equal(1, BigDecimal.new("1", 1)) @@ -70,6 +78,14 @@ class TestBigDecimal < Test::Unit::TestCase assert_raise(ArgumentError) { BigDecimal.new(1.quo(3)) } end + def test_new_with_float + assert_equal(BigDecimal("0.1235"), BigDecimal(0.1234567, 4)) + assert_equal(BigDecimal("-0.1235"), BigDecimal(-0.1234567, 4)) + assert_raise(ArgumentError) { BigDecimal.new(0.1) } + assert_raise(ArgumentError) { BigDecimal.new(0.1, Float::DIG + 2) } + assert_nothing_raised { BigDecimal.new(0.1, Float::DIG + 1) } + end + def _test_mode(type) BigDecimal.mode(type, true) assert_raise(FloatDomainError) { yield } |