Skip to content
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

Fix BigDecimal#round behavior with NAN and INFINITY #1808

merged 1 commit into from Jul 25, 2014

Fix BigDecimal#round behavior with NAN and INFINITY #1808

merged 1 commit into from Jul 25, 2014


Copy link

@robin850 robin850 commented Jul 12, 2014


JRuby's behavior of BigDecimal#round with BigDecimal::NAN and BigDecimal::INFINITY is kind of weird as it computes a value of 0.0. Currently, the problem is that under the hood, JRuby defines the constant according to BigDecimal.ZERO and round uses the value to compute the "rounding" but it should simply return the constant itself.

Moreover, when we call #round without any argument on these constants, a FloatDomainError should be raised.

This area of code on this branch is a bit different from master so here's a diff that you can git apply to simplify the merge process between branches.

Have a nice day.

@enebo enebo added this to the JRuby 1.7.14 milestone Jul 16, 2014
When we call round without any argument on BigDecimal::NAN or
BigDecimal::INFINITY, a FloatDomainError should be raised.

Otherwise, the number shouldn't be altered. The problem is that JRuby
defines these constants according to BigDecimal.ZERO so when we apply
the rounding on it, it returns a float form of 0. Thus, we need to
short-circuit that and return the constant itself.
headius added a commit that referenced this pull request Jul 25, 2014
Fix BigDecimal#round behavior with NAN and INFINITY
@headius headius merged commit 7211c60 into jruby:jruby-1_7 Jul 25, 2014
1 check failed
1 check failed
continuous-integration/travis-ci The Travis CI build failed
@robin850 robin850 deleted the robin850:bigdecimal-round branch Jul 25, 2014
Copy link
Contributor Author

@robin850 robin850 commented Jul 25, 2014


Copy link

@headius headius commented Jul 25, 2014

No, thank you!

@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.15 Aug 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants