
Issue #20654 has been updated by peterzhu2118 (Peter Zhu). I opened backport PRs. 3.3: https://github.com/ruby/ruby/pull/11277 3.2: https://github.com/ruby/ruby/pull/11278 ---------------------------------------- Bug #20654: Floor and ceil have unexpected behaviour when ndigits is large https://bugs.ruby-lang.org/issues/20654#change-109280 * Author: peterzhu2118 (Peter Zhu) * Status: Closed * Backport: 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED ---------------------------------------- GitHub PR: https://github.com/ruby/ruby/pull/11257 There is unexpected behaviour in Integer#floor, Float#floor, Integer#ceil, Float#ceil when ndigits is large such that 10**ndigits is a bignum. Previously, it would return 0 in such cases. However, this would cause unexpected behaviour such as: ```ruby puts -1.floor(-5) # => -100000 puts -1.floor(-10) # => -10000000000 puts -1.floor(-20) # => 0 ``` ```ruby puts 1.ceil(-5) # => 100000 puts 1.ceil(-10) # => 10000000000 puts 1.ceil(-20) # => 0 ``` The PR changes the last result so that it will return -100000000000000000000 and 100000000000000000000, respectively. -- https://bugs.ruby-lang.org/