Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat Fraction as a real value in mixed arithmetic operations with complex #119838

Closed
serhiy-storchaka opened this issue May 31, 2024 · 2 comments

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented May 31, 2024

In arithmetic operations, if one of operands is a Fraction, and the other operand is a complex or a numbers.Complex, the fraction is implicitly converted to a complex. Third-party types implementing the numbers.Complex interface can distinguish between real and complex operands. In future we can support the mixed real-complex arithmetic also for the builtin complex type. A fraction is a real value, so it makes sense to convert it to float instead of complex in such cases.

Linked PRs

@skirpichev
Copy link
Member

skirpichev commented May 31, 2024

In future we can support the mixed real-complex arithmetic also for the builtin complex type.

Then this change will make sense. Right now it contradicts to coercion rules for int/floats op complex.

PS: But thank you for reminding me that I should fix also the "complex op Fraction" case in my pr:)

Edit: After looking on the code, sorry - false alert.

@mdickinson
Copy link
Member

A fraction is a real value, so it makes sense to convert it to float instead of complex in such cases.

+1

mliezun pushed a commit to mliezun/cpython that referenced this issue Jun 3, 2024
barneygale pushed a commit to barneygale/cpython that referenced this issue Jun 5, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
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

No branches or pull requests

3 participants