Skip to content

Commit

Permalink
Added in-place Int functionality for VOC
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonscotthammond committed Aug 5, 2017
1 parent de4395b commit 0012c08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 23 additions & 0 deletions python/common/org/python/types/Int.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ public org.python.Object __iadd__(org.python.Object other) {
} else if (other instanceof org.python.types.Bool) {
this.value += (((org.python.types.Bool) other).value ? 1 : 0);
return new org.python.types.Int(this.value);
} else if (other instanceof org.python.types.Complex) {
org.python.types.Complex other_cmplx_obj = (org.python.types.Complex) other;
return new org.python.types.Complex(this.value + other_cmplx_obj.real.value, other_cmplx_obj.imag.value);
}
throw new org.python.exceptions.TypeError("unsupported operand type(s) for +=: 'int' and '" + other.typeName() + "'");
}
Expand All @@ -680,7 +683,27 @@ public org.python.Object __ilshift__(org.python.Object other) {
@org.python.Method(
__doc__ = ""
)
public org.python.Object __isub__(org.python.Object other) {
if (other instanceof org.python.types.Int) {
this.value -= ((org.python.types.Int) other).value;
return new org.python.types.Int(this.value);
} else if (other instanceof org.python.types.Float) {
double this_val = this.value;
this_val -= ((org.python.types.Float) other).value;
return new org.python.types.Float(this_val);
} else if (other instanceof org.python.types.Bool) {
this.value -= (((org.python.types.Bool) other).value ? 1 : 0);
return new org.python.types.Int(this.value);
} else if (other instanceof org.python.types.Complex) {
org.python.types.Complex other_cmplx_obj = (org.python.types.Complex) other;
return new org.python.types.Complex(this.value - other_cmplx_obj.real.value, -(other_cmplx_obj.imag.value));
}
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -=: 'int' and '" + other.typeName() + "'");
}

@org.python.Method(
__doc__ = ""
)
public org.python.Object __itruediv__(org.python.Object other) {
if (other instanceof org.python.types.Int || other instanceof org.python.types.Float || other instanceof org.python.types.Bool) {
return this.__truediv__(other);
Expand Down
5 changes: 0 additions & 5 deletions tests/datatypes/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class InplaceIntOperationTests(InplaceOperationTestCase, TranspileTestCase):
data_type = 'int'

not_implemented = [
'test_add_complex',

'test_floor_divide_float',

Expand All @@ -71,9 +70,5 @@ class InplaceIntOperationTests(InplaceOperationTestCase, TranspileTestCase):
'test_power_float',
'test_power_int',


'test_subtract_complex',
'test_subtract_float',

'test_true_divide_complex',
]

0 comments on commit 0012c08

Please sign in to comment.