Fix BigDecimal#round behavior with NAN and INFINITY #1808

Merged
merged 1 commit into from Jul 25, 2014

Projects

None yet

3 participants

@robin850
Contributor

Hello,

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.

@robin850 robin850 referenced this pull request in rubysl/rubysl-bigdecimal Jul 15, 2014
Merged

Add specs for BigDecimal#round with NaN and Infinity #3

@enebo enebo added this to the JRuby 1.7.14 milestone Jul 16, 2014
@robin850 robin850 Fix BigDecimal#round behavior with NAN and INFINITY
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.
faae599
@headius headius merged commit 7211c60 into jruby:jruby-1_7 Jul 25, 2014

1 check failed

continuous-integration/travis-ci The Travis CI build failed
Details
@robin850 robin850 deleted the robin850:bigdecimal-round branch Jul 25, 2014
@robin850
Contributor

Thanks!

@headius
Member
headius commented Jul 25, 2014

No, thank you!

@enebo enebo modified the milestone: 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