Skip to content

Commit 029d980

Browse files
committed
support booleans in int.__abs__ and int.__invert__
1 parent dff4df6 commit 029d980

File tree

1 file changed

+10
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints

1 file changed

+10
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,11 @@ private BigInteger op(BigInteger a, long b) {
919919
@Builtin(name = SpecialMethodNames.__ABS__, fixedNumOfArguments = 1)
920920
@GenerateNodeFactory
921921
abstract static class AbsNode extends PythonUnaryBuiltinNode {
922+
@Specialization
923+
boolean pos(boolean arg) {
924+
return arg;
925+
}
926+
922927
@Specialization(rewriteOn = ArithmeticException.class)
923928
int pos(int arg) {
924929
int result = Math.abs(arg);
@@ -1068,6 +1073,11 @@ static BigInteger negate(BigInteger value) {
10681073
@Builtin(name = SpecialMethodNames.__INVERT__, fixedNumOfArguments = 1)
10691074
@GenerateNodeFactory
10701075
abstract static class InvertNode extends PythonUnaryBuiltinNode {
1076+
@Specialization
1077+
int neg(boolean arg) {
1078+
return ~(arg ? 1 : 0);
1079+
}
1080+
10711081
@Specialization
10721082
int neg(int arg) {
10731083
return ~arg;

0 commit comments

Comments
 (0)