Complex and ints addition#523
Complex and ints addition#523OddCoincidence merged 2 commits intoRustPython:masterfrom AdamGS:complex_and_ints_addition
Conversation
Codecov Report
@@ Coverage Diff @@
## master #523 +/- ##
==========================================
- Coverage 50.34% 50.17% -0.18%
==========================================
Files 68 68
Lines 13868 13923 +55
Branches 3436 3456 +20
==========================================
+ Hits 6982 6986 +4
- Misses 5035 5083 +48
- Partials 1851 1854 +3
Continue to review full report at Codecov.
|
vm/src/obj/objint.rs
Outdated
| ); | ||
| if objtype::isinstance(other, &vm.ctx.int_type()) { | ||
| Ok(vm.ctx.new_int(get_value(zelf) + get_value(other))) | ||
| } else if objtype::isinstance(other, &vm.ctx.complex_type()) { |
There was a problem hiding this comment.
how acout add __radd__ to the complex instead? This way int object doesn't have to know about operations on complex numbers.
There was a problem hiding this comment.
Didn't know about __radd__ ! will do.
There was a problem hiding this comment.
(technically, CPython uses the same C function for both 1+1j and 1j+1 - it promotes any side to complex if needed. However, I'd assume that since we can't do it this way now, __radd__ would be closer to expected behavior)
Adds the option to add complex number to ints, and also to create a new complex number just by
instead of