From d56b2776847f91fea70a3008ce29be544343f770 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 13 Apr 2016 06:54:38 +0000 Subject: numeric.c: flo_floor * numeric.c (flo_floor): add an optional parameter, digits, as well as Integer#floor. [Feature #12245] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_float.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index aeac359081..9deed4dea4 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -444,6 +444,28 @@ class TestFloat < Test::Unit::TestCase assert_equal(1.0, 0.998.round(prec)) end + def test_floor_with_precision + assert_equal(1.100, 1.111.floor(1)) + assert_equal(1.110, 1.111.floor(2)) + assert_equal(11110, 11119.9.floor(-1)) + assert_equal(11100, 11100.0.floor(-2)) + assert_equal(11100, 11199.9.floor(-2)) + assert_equal(0, 11111.1.floor(-5)) + + assert_equal(10**300, 1.1e300.floor(-300)) + assert_equal(-2*10**300, -1.1e300.floor(-300)) + assert_equal(1.0e-300, 1.1e-300.floor(300)) + assert_equal(-2.0e-300, -1.1e-300.floor(300)) + + assert_equal(42.0, 42.0.floor(308)) + assert_equal(1.0e307, 1.0e307.floor(2)) + + assert_raise(TypeError) {1.0.floor("4")} + assert_raise(TypeError) {1.0.floor(nil)} + def (prec = Object.new).to_int; 2; end + assert_equal(0.99, 0.998.floor(prec)) + end + VS = [ 18446744073709551617.0, 18446744073709551616.0, -- cgit v1.2.3