From c4eb2983bac76f60e0d3fe958b74237e2aac90d6 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 1 Sep 2011 16:07:16 +0000 Subject: * numeric.c (flo_round): substitute machine dependent magic number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_float.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/ruby/test_float.rb') 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 = [ -- cgit v1.2.3