|
25 | 25 | */ |
26 | 26 | package com.oracle.graal.python.builtins.objects.floats; |
27 | 27 |
|
28 | | -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; |
29 | 28 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError; |
| 29 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; |
30 | 30 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError; |
31 | 31 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ABS__; |
32 | 32 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ADD__; |
33 | 33 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__BOOL__; |
| 34 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__DIVMOD__; |
34 | 35 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__; |
35 | 36 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOAT__; |
36 | 37 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOORDIV__; |
|
48 | 49 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__POS__; |
49 | 50 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__POW__; |
50 | 51 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RADD__; |
| 52 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__RDIVMOD__; |
51 | 53 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__; |
52 | 54 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RFLOORDIV__; |
53 | 55 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RMOD__; |
@@ -598,6 +600,37 @@ PNotImplemented doGeneric(Object left, Object right) { |
598 | 600 | } |
599 | 601 | } |
600 | 602 |
|
| 603 | + @Builtin(name = __RDIVMOD__, minNumOfPositionalArgs = 2, reverseOperation = true) |
| 604 | + @Builtin(name = __DIVMOD__, minNumOfPositionalArgs = 2) |
| 605 | + @TypeSystemReference(PythonArithmeticTypes.class) |
| 606 | + @GenerateNodeFactory |
| 607 | + abstract static class DivModNode extends FloatBinaryBuiltinNode { |
| 608 | + @Specialization |
| 609 | + PTuple doDL(double left, long right) { |
| 610 | + raiseDivisionByZero(right == 0); |
| 611 | + return factory().createTuple(new Object[]{Math.floor(left / right), left % right}); |
| 612 | + } |
| 613 | + |
| 614 | + @Specialization |
| 615 | + PTuple doDD(double left, double right) { |
| 616 | + raiseDivisionByZero(right == 0.0); |
| 617 | + return factory().createTuple(new Object[]{Math.floor(left / right), left % right}); |
| 618 | + } |
| 619 | + |
| 620 | + @Specialization |
| 621 | + PTuple doLD(long left, double right) { |
| 622 | + raiseDivisionByZero(right == 0.0); |
| 623 | + return factory().createTuple(new Object[]{Math.floor(left / right), left % right}); |
| 624 | + } |
| 625 | + |
| 626 | + @Specialization |
| 627 | + PTuple doGeneric(VirtualFrame frame, Object left, Object right, |
| 628 | + @Cached FloorDivNode floorDivNode, |
| 629 | + @Cached ModNode modNode) { |
| 630 | + return factory().createTuple(new Object[]{floorDivNode.execute(frame, left, right), modNode.execute(frame, left, right)}); |
| 631 | + } |
| 632 | + } |
| 633 | + |
601 | 634 | @Builtin(name = SpecialMethodNames.__HASH__, minNumOfPositionalArgs = 1) |
602 | 635 | @GenerateNodeFactory |
603 | 636 | @TypeSystemReference(PythonArithmeticTypes.class) |
|
0 commit comments