Skip to content

Commit

Permalink
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -248,6 +248,19 @@ public Object sub(VirtualFrame frame, int a, RubyBasicObject b) {
return rationalSubNode.call(frame, aRational, "-", null, b);
}

@Specialization(guards = "isRational(arguments[1])")
public Object sub(VirtualFrame frame, long a, RubyBasicObject b) {
if (rationalConvertNode == null) {
CompilerDirectives.transferToInterpreter();
rationalConvertNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
rationalSubNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object aRational = rationalConvertNode.call(frame, getContext().getCoreLibrary().getRationalClass(), "convert", null, a, 1);

return rationalSubNode.call(frame, aRational, "-", null, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long sub(long a, int b) {
return ExactMath.subtractExact(a, b);

0 comments on commit 73bbd14

Please sign in to comment.