GeezerVison is showing github.com — Treat Fraction as a real value in mixed arithmetic operations with complex · Issue #119838 · python/cpython
Treat Fraction as a real value in mixed arithmetic operations with complex #119838
Description
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
Activity
skirpichev commented on 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 commented on Jun 2, 2024
A fraction is a real value, so it makes sense to convert it to float instead of complex in such cases.
+1
added a commit that references this issue
on Jun 3, 2024gh-119838: Treat Fraction as a real value in mixed arithmetic operati…
Metadata
Metadata
Development
No branches or pull requestsIssue actions