Skip to content

Commit

Permalink
[Truffle] Throw a proper error on Bignum / 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 2, 2016
1 parent 9851022 commit 828a0db
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -145,6 +145,9 @@ public abstract static class DivNode extends BignumCoreMethodNode {
@TruffleBoundary
@Specialization
public Object div(DynamicObject a, long b) {
if (b == 0) {
throw new RaiseException(coreExceptions().zeroDivisionError(this));
}
final BigInteger bBigInt = BigInteger.valueOf(b);
final BigInteger aBigInt = Layouts.BIGNUM.getValue(a);
final BigInteger result = aBigInt.divide(bBigInt);
Expand All @@ -166,6 +169,9 @@ public double div(DynamicObject a, double b) {
public Object div(DynamicObject a, DynamicObject b) {
final BigInteger aBigInt = Layouts.BIGNUM.getValue(a);
final BigInteger bBigInt = Layouts.BIGNUM.getValue(b);
if (b.equals(BigInteger.ZERO)) {
throw new RaiseException(coreExceptions().zeroDivisionError(this));
}
final BigInteger result = aBigInt.divide(bBigInt);
if (result.signum() == -1 && !aBigInt.mod(bBigInt.abs()).equals(BigInteger.ZERO)) {
return fixnumOrBignum(result.subtract(BigInteger.ONE));
Expand Down

0 comments on commit 828a0db

Please sign in to comment.