Skip to content

Commit 8cce3b0

Browse files
committed
[GR-20835] Operations lt, le, gt and ge for two complex numbers should return NotImplemented.
1 parent d65a248 commit 8cce3b0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_complex.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
*ComplexTest.test_overflow
1111
*ComplexTest.test_plus_minus_0j
1212
*ComplexTest.test_repr_str
13+
*ComplexTest.test_richcompare
1314
*ComplexTest.test_truediv

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ PNotImplemented doGeneric(Object left, Object right) {
498498
@Builtin(name = __GE__, minNumOfPositionalArgs = 2)
499499
abstract static class GeNode extends PythonBinaryBuiltinNode {
500500
@Specialization
501-
boolean doComplex(PComplex left, PComplex right) {
502-
return left.greaterEqual(right);
501+
PNotImplemented doComplex(PComplex left, PComplex right) {
502+
return PNotImplemented.NOT_IMPLEMENTED;
503503
}
504504

505505
@SuppressWarnings("unused")
@@ -513,8 +513,8 @@ PNotImplemented doGeneric(Object left, Object right) {
513513
@Builtin(name = __GT__, minNumOfPositionalArgs = 2)
514514
abstract static class GtNode extends PythonBinaryBuiltinNode {
515515
@Specialization
516-
boolean doComplex(PComplex left, PComplex right) {
517-
return left.greaterThan(right);
516+
PNotImplemented doComplex(PComplex left, PComplex right) {
517+
return PNotImplemented.NOT_IMPLEMENTED;
518518
}
519519

520520
@SuppressWarnings("unused")
@@ -528,8 +528,8 @@ PNotImplemented doGeneric(Object left, Object right) {
528528
@Builtin(name = __LT__, minNumOfPositionalArgs = 2)
529529
abstract static class LtNode extends PythonBinaryBuiltinNode {
530530
@Specialization
531-
boolean doComplex(PComplex left, PComplex right) {
532-
return left.lessThan(right);
531+
PNotImplemented doComplex(PComplex left, PComplex right) {
532+
return PNotImplemented.NOT_IMPLEMENTED;
533533
}
534534

535535
@SuppressWarnings("unused")
@@ -543,8 +543,8 @@ PNotImplemented doGeneric(Object left, Object right) {
543543
@Builtin(name = __LE__, minNumOfPositionalArgs = 2)
544544
abstract static class LeNode extends PythonBinaryBuiltinNode {
545545
@Specialization
546-
boolean doComplex(PComplex left, PComplex right) {
547-
return left.lessEqual(right);
546+
PNotImplemented doComplex(PComplex left, PComplex right) {
547+
return PNotImplemented.NOT_IMPLEMENTED;
548548
}
549549

550550
@SuppressWarnings("unused")
@@ -567,6 +567,16 @@ boolean doComplex(PComplex left, PComplex right) {
567567
boolean doComplex(PComplex left, long right) {
568568
return left.getImag() != 0 || left.getReal() != right;
569569
}
570+
571+
@Specialization
572+
boolean doComplex(PComplex left, PInt right) {
573+
return left.getImag() != 0 || left.getReal() != right.doubleValue();
574+
}
575+
576+
@Specialization
577+
boolean doComplex(PComplex left, double right) {
578+
return left.getImag() != 0 || left.getReal() != right;
579+
}
570580

571581
@SuppressWarnings("unused")
572582
@Fallback

0 commit comments

Comments
 (0)