aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_float.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r--test/ruby/test_float.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index fb37d73831..c244447bd7 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -315,7 +315,9 @@ class TestFloat < Test::Unit::TestCase
assert_raise(FloatDomainError) { inf.ceil }
assert_raise(FloatDomainError) { inf.round }
assert_raise(FloatDomainError) { inf.truncate }
+ end
+ def test_round_with_precision
assert_equal(1.100, 1.111.round(1))
assert_equal(1.110, 1.111.round(2))
assert_equal(11110.0, 11111.1.round(-1))
@@ -323,6 +325,17 @@ class TestFloat < Test::Unit::TestCase
assert_equal(10**300, 1.1e300.round(-300))
assert_equal(-10**300, -1.1e300.round(-300))
+ assert_equal(1.0e-300, 1.1e-300.round(300))
+ assert_equal(-1.0e-300, -1.1e-300.round(300))
+
+ bug5227 = '[ruby-core:39093]'
+ assert_equal(42.0, 42.0.round(308), bug5227)
+ assert_equal(1.0e307, 1.0e307.round(2), bug5227)
+
+ assert_raise(TypeError) {1.0.round("4")}
+ assert_raise(TypeError) {1.0.round(nil)}
+ def (prec = Object.new).to_int; 2; end
+ assert_equal(1.0, 0.998.round(prec))
end
VS = [