8000 [Backport 3.3] [Bug #20654] Fix floor and ceil when ndigits is large by peterzhu2118 · Pull Request #11277 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

[Backport 3.3] [Bug #20654] Fix floor and ceil when ndigits is large #11277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

peterzhu2118
Copy link
Member

This PR fixes 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:

puts -1.floor(-5) # => -100000
puts -1.floor(-10) # => -10000000000
puts -1.floor(-20) # => 0
puts 1.ceil(-5) # => 100000
puts 1.ceil(-10) # => 10000000000
puts 1.ceil(-20) # => 0

This commit changes the last result so that it will return -100000000000000000000 and 100000000000000000000, respectively.

[Bug #20654]

This commit fixes Integer#floor and Float#floor when the number is
negative and 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:

    puts -1.floor(-5) # => -100000
    puts -1.floor(-10) # => -10000000000
    puts -1.floor(-20) # => 0

This commit changes the last result so that it will return
-100000000000000000000.
@peterzhu2118 peterzhu2118 requested a review from k0kubun as a code owner July 30, 2024 12:48
[Bug #20654]

This commit fixes Integer#ceil and Float#ceil when the number is
negative and 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:

    puts 1.ceil(-5) # => 100000
    puts 1.ceil(-10) # => 10000000000
    puts 1.ceil(-20) # => 0

This commit changes the last result so that it will return
100000000000000000000.
@peterzhu2118 peterzhu2118 force-pushed the backport-3-3-ceil-floor-large-ndigit branch from b93ff6b to 1a46429 Compare July 30, 2024 13:04
@k0kubun k0kubun merged commit 0922afa into ruby:ruby_3_3 Jul 30, 2024
95 of 96 checks passed
@peterzhu2118 peterzhu2118 deleted the backport-3-3-ceil-floor-large-ndigit branch July 30, 2024 16:23
@hsbt hsbt added the Backport label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0