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: b2d95821974f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2005fa7c1420
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on May 25, 2016

  1. Copy the full SHA
    c69832c View commit details

Commits on Aug 23, 2016

  1. Merge pull request #3927 from ahorek/backport_to_r_fix

    backport BigDecimal .to_r for #3728
    headius authored Aug 23, 2016
    Copy the full SHA
    2005fa7 View commit details
Showing with 5 additions and 25 deletions.
  1. +5 −25 core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
30 changes: 5 additions & 25 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -566,7 +566,7 @@ else if (isExponentOutOfRange(expValue)) {
else if ( ( idx = matcher.start(3) ) > 0 ) {
strValue = strValue.substring(0, idx); // ignored tail junk e.g. "5-6" -> "-6"
}

BigDecimal decimal;
try {
decimal = new BigDecimal(strValue, mathContext);
@@ -1795,31 +1795,11 @@ public IRubyObject to_int() {
public IRubyObject to_r(ThreadContext context) {
checkFloatDomain();

RubyArray i = split();
long sign = ((Long)i.get(0));
String digits = (String)i.get(1).toString();
long base = ((Long)i.get(2));
long power = ((Long)i.get(3));
long denomi_power = power - digits.length();
int scale = value.scale();
BigInteger numerator = value.scaleByPowerOfTen(scale).toBigInteger();
BigInteger denominator = BigInteger.valueOf((long)Math.pow(10, scale));

IRubyObject bigDigits = RubyBignum.newBignum(getRuntime(), (String)digits).op_mul(context, sign);
RubyBignum numerator;
if(bigDigits instanceof RubyBignum) {
numerator = (RubyBignum)bigDigits;
}
else {
numerator = RubyBignum.newBignum(getRuntime(), bigDigits.toString());
}
IRubyObject num, den;
if(denomi_power < 0) {
num = numerator;
den = RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), -denomi_power));
}
else {
num = numerator.op_pow(context, RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), denomi_power)));
den = RubyFixnum.newFixnum(getRuntime(), 1);
}
return RubyRational.newInstance(context, context.runtime.getRational(), num, den);
return RubyRational.newInstance(context, context.runtime.getRational(), RubyBignum.newBignum(context.runtime, numerator), RubyBignum.newBignum(context.runtime, denominator));
}

@JRubyMethod(name = {"to_i", "to_int"}, compat = CompatVersion.RUBY1_9)