diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-13 06:54:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-13 06:54:38 +0000 |
commit | d4d40eabc42c11ceef64893c9210f67c7729a02b (patch) | |
tree | b371d9e362af746914adfac2c19e437037f6b2d7 /test/ruby/test_float.rb | |
parent | 4fda87a0b4b644620568fe62490ef51c7aa1a807 (diff) | |
download | ruby-d4d40eabc42c11ceef64893c9210f67c7729a02b.tar.gz |
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
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r-- | test/ruby/test_float.rb | 22 |
1 files changed, 22 insertions, 0 deletions
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, |