aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 06:54:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 06:54:38 +0000
commitd56b2776847f91fea70a3008ce29be544343f770 (patch)
treeb371d9e362af746914adfac2c19e437037f6b2d7 /test
parenta1542d33ca30cdecb741be526d043be6bba01d76 (diff)
downloadruby-d56b2776847f91fea70a3008ce29be544343f770.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')
-rw-r--r--test/ruby/test_float.rb22
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,