Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ceb199a1416b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8a4ffea16fa2
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Sep 29, 2014

  1. fixed issue 1695

    k77ch7 committed Sep 29, 2014
    Copy the full SHA
    174117d View commit details

Commits on Nov 2, 2014

  1. Merge pull request #2011 from k77ch7/GH-1695_big_decimal_and_rational…

    …_multiplication
    
    Fix for issue 1695 : BigDecimal and Rational multiplication
    headius committed Nov 2, 2014
    Copy the full SHA
    8a4ffea View commit details
13 changes: 8 additions & 5 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -458,11 +458,14 @@ private static RubyBigDecimal getVpValue19(ThreadContext context, IRubyObject v,
}

private static IRubyObject getVpRubyObjectWithPrec19Inner(ThreadContext context, RubyRational r, long precision, boolean must) {
long numerator = RubyNumeric.num2long(r.numerator(context));
long denominator = RubyNumeric.num2long(r.denominator(context));

return new RubyBigDecimal(context.runtime,
BigDecimal.valueOf(numerator).divide(BigDecimal.valueOf(denominator), getRoundingMode(context.runtime)));
BigDecimal numerator = BigDecimal.valueOf(RubyNumeric.num2long(r.numerator(context)));
BigDecimal denominator = BigDecimal.valueOf(RubyNumeric.num2long(r.denominator(context)));

int len = numerator.precision() + denominator.precision();
int pow = len / 4;
MathContext mathContext = new MathContext((pow + 1) * 4, getRoundingMode(context.runtime));

return new RubyBigDecimal(context.runtime, numerator.divide(denominator, mathContext));
}

private static RubyBigDecimal getVpValueWithPrec19(ThreadContext context, IRubyObject value, long precision, boolean must) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rational'
require 'bigdecimal'

# https://github.com/jruby/jruby/issues/1695
describe 'BigDecimal#*' do
it 'returns correct value' do
(BigDecimal.new('100') * Rational(1, 100)).to_i.should == 1
(BigDecimal.new('100') * Rational(49, 100)).to_i.should == 49
(BigDecimal.new('100') * Rational(50, 100)).to_i.should == 50
end
end