aboutsummaryrefslogtreecommitdiffstats
path: root/test/bigdecimal/test_bigdecimal.rb
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-18 20:19:38 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-18 20:19:38 +0000
commit3cbda570c22f0324502a43dc668223b3da5d241b (patch)
tree01a39613da904d9358d63140eef7e17cae8ccbc7 /test/bigdecimal/test_bigdecimal.rb
parent9dffbcfc09dc54d77bfb99dc91e0c5ea01182925 (diff)
downloadruby-3cbda570c22f0324502a43dc668223b3da5d241b.tar.gz
* ext/bigdecimal/bigdecimal.c: fix rounding algorithms for half-down
and half-even. This change is based on the patch created by Matthew Willson, the reporter of this bug. [Bug #3803] [ruby-core:32136] * test/bigdecimal/test_bigdecimal.rb: add tests for above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal/test_bigdecimal.rb')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 02a067a810..2efa65b57b 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -612,6 +612,18 @@ class TestBigDecimal < Test::Unit::TestCase
assert_equal(3, x.round(0, BigDecimal::ROUND_CEILING))
assert_equal(2, x.round(0, BigDecimal::ROUND_FLOOR))
assert_raise(TypeError) { x.round(0, 256) }
+
+ 15.times do |n|
+ x = BigDecimal.new("5#{'0'*n}1")
+ assert_equal(10**(n+2), x.round(-(n+2), BigDecimal::ROUND_HALF_DOWN))
+ assert_equal(10**(n+2), x.round(-(n+2), BigDecimal::ROUND_HALF_EVEN))
+ x = BigDecimal.new("0.5#{'0'*n}1")
+ assert_equal(1, x.round(0, BigDecimal::ROUND_HALF_DOWN))
+ assert_equal(1, x.round(0, BigDecimal::ROUND_HALF_EVEN))
+ x = BigDecimal.new("-0.5#{'0'*n}1")
+ assert_equal(-1, x.round(0, BigDecimal::ROUND_HALF_DOWN))
+ assert_equal(-1, x.round(0, BigDecimal::ROUND_HALF_EVEN))
+ end
end
def test_truncate