Skip to content

Commit 231d1f2

Browse files
committed
Try getting bigint negative modulo working.
1 parent d4a13c5 commit 231d1f2

File tree

1 file changed

+9
-1
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+9
-1
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4221,7 +4221,15 @@ public static double div_In(SixModelObject a, SixModelObject b, ThreadContext tc
42214221
}
42224222

42234223
public static SixModelObject mod_I(SixModelObject a, SixModelObject b, SixModelObject type, ThreadContext tc) {
4224-
return makeBI(tc, type, getBI(tc, a).mod(getBI(tc, b)));
4224+
BigInteger divisor = getBI(tc, b);
4225+
if (divisor.compareTo(BigInteger.ZERO) < 0) {
4226+
BigInteger negDivisor = divisor.negate();
4227+
BigInteger res = getBI(tc, a).mod(negDivisor);
4228+
return makeBI(tc, type, res.equals(BigInteger.ZERO) ? res : divisor.add(res));
4229+
}
4230+
else {
4231+
return makeBI(tc, type, getBI(tc, a).mod(divisor));
4232+
}
42254233
}
42264234

42274235
public static SixModelObject expmod_I(SixModelObject a, SixModelObject b, SixModelObject c, SixModelObject type, ThreadContext tc) {

0 commit comments

Comments
 (0)