Skip to content

Conversation

@AdamGS
Copy link
Contributor

@AdamGS AdamGS commented Feb 22, 2019

Adds the option to add complex number to ints, and also to create a new complex number just by

cmplx = 1 + 1j

instead of

cmplx = Complex(1, 1)

@codecov-io
Copy link

codecov-io commented Feb 22, 2019

Codecov Report

Merging #523 into master will decrease coverage by 0.17%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
vm/src/obj/objcomplex.rs 47.05% <33.33%> (-22.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c22fb58...f333c75. Read the comment docs.

);
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()) {
Copy link
Contributor

@adrian17 adrian17 Feb 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how acout add __radd__ to the complex instead? This way int object doesn't have to know about operations on complex numbers.

Copy link
Contributor Author

@AdamGS AdamGS Feb 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about __radd__ ! will do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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)

@OddCoincidence OddCoincidence merged commit 2df7414 into RustPython:master Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants