diff options
author | Jeremy Evans <[email protected]> | 2021-07-26 10:45:56 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2021-07-27 11:00:45 -0700 |
commit | 35e467080ca35a9a129e95f802f102c3bc0a81b3 (patch) | |
tree | 162489bbf3dd40c61af61f0fe2f452205957126b /test | |
parent | 338b604b3216b633d0fc897a915168104f20a514 (diff) |
Make Float#floor with ndigits argument handle error
The previous implementation could result in a returned
float that is 1/(10**ndigits) too low. First try adding
one before dividing, and if that results in a value that is
greater than the initial number, then try the original
calculation.
Spec added for ciel, but the issue doesn't appear to affect
ciel, at least not for the same number. If the issue does
effect ciel, a similar fix could probably work for it.
Fixes [Bug #18018]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4681
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_numeric.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 066afc83a2..b5486d387c 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -229,6 +229,15 @@ class TestNumeric < Test::Unit::TestCase assert_equal(-1, a.truncate) end + def test_floor_ceil_ndigits + bug17183 = "[ruby-core:100090]" + f = 291.4 + 31.times do |i| + assert_equal(291.4, f.floor(i+1), bug17183) + assert_equal(291.4, f.ceil(i+1), bug17183) + end + end + def assert_step(expected, (from, *args), inf: false) kw = args.last.is_a?(Hash) ? args.pop : {} enum = from.step(*args, **kw) |