diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-08 11:20:51 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-08 11:20:51 +0000 |
commit | 0727a22c69641c98edd50668322d8f0270bec457 (patch) | |
tree | 3be4ccaa17b4a7a14baa19896aa648be49247514 /test/bigdecimal | |
parent | e54e3d70a8f70ec0f6426e29dcde9bff884dc8d0 (diff) | |
download | ruby-0727a22c69641c98edd50668322d8f0270bec457.tar.gz |
* bigdecimal.c (BigDecimal_coerce): convert a Float to a BigDecimal instead
of converting the receiver to a Float.
[ruby-core:58756] [Bug #9192]
* test/bigdecimal/test_bigdecimal.rb: add tests for the above change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 6df858c7c4..e7bb1c513d 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -438,6 +438,20 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(0, BigDecimal("1E-1") <=> 10**(-1), '#4825') end + def test_cmp_issue9192 + bug9192 = '[ruby-core:58756] [#9192]' + operators = { :== => :==, :< => :>, :> => :<, :<= => :>=, :>= => :<= } + 5.upto(8) do |i| + s = "706.0#{i}" + d = BigDecimal(s) + f = s.to_f + operators.each do |op, inv| + assert_equal(d.send(op, f), f.send(inv, d), + "(BigDecimal(#{s.inspect}) #{op} #{s}) and (#{s} #{inv} BigDecimal(#{s.inspect})) is different #{bug9192}") + end + end + end + def test_cmp_nan n1 = BigDecimal.new("1") BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) @@ -608,8 +622,8 @@ class TestBigDecimal < Test::Unit::TestCase def test_coerce a, b = BigDecimal.new("1").coerce(1.0) - assert_instance_of(Float, a) - assert_instance_of(Float, b) + assert_instance_of(BigDecimal, a) + assert_instance_of(BigDecimal, b) assert_equal(2, 1 + BigDecimal.new("1"), '[ruby-core:25697]') a, b = BigDecimal("1").coerce(1.quo(10)) @@ -1462,7 +1476,7 @@ class TestBigDecimal < Test::Unit::TestCase def test_BigMath_log_with_101 # this is mainly a performance test (should be very fast, not the 0.3 s) - assert_in_delta(Math.log(101), BigMath.log(101, 20), 1E-20) + assert_in_delta(Math.log(101), BigMath.log(101, 20), 1E-15) end def test_BigMath_log_with_reciprocal_of_42 |