Skip to content

Commit b6d7fca

Browse files
committed
Avoid corner cases in mixed calculations with 'complex'.
See python/cpython#119839
1 parent 509036c commit b6d7fca

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGES.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ ChangeLog
99
* Generally use ``.as_integer_ratio()`` in the constructor if available.
1010
https://github.com/python/cpython/pull/120271
1111

12-
* Using ``complex`` numbers in division shows better tracebacks.
13-
https://github.com/python/cpython/pull/102842
14-
1512
* Mixed calculations with other ``Rational`` classes could return the wrong type.
1613
https://github.com/python/cpython/issues/119189
1714

15+
* In mixed calculations with ``complex``, the Fraction is now converted to ``float``
16+
instead of ``complex`` to avoid certain corner cases in complex calculation.
17+
https://github.com/python/cpython/pull/119839
18+
19+
* Using ``complex`` numbers in division shows better tracebacks.
20+
https://github.com/python/cpython/pull/102842
21+
1822

1923
1.18 (2024-04-03)
2024
-----------------

src/quicktions.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ cdef forward(a, b, math_func monomorphic_operator, pyoperator, handle_complex=Tr
14941494
elif isinstance(b, float):
14951495
return pyoperator(_as_float(an, ad), b)
14961496
elif handle_complex and isinstance(b, complex):
1497-
return pyoperator(complex(a), b)
1497+
return pyoperator(float(a), b)
14981498
else:
14991499
return NotImplemented
15001500

@@ -1508,7 +1508,7 @@ cdef reverse(a, b, math_func monomorphic_operator, pyoperator, handle_complex=Tr
15081508
elif isinstance(a, Real):
15091509
return pyoperator(float(a), _as_float(bn, bd))
15101510
elif handle_complex and isinstance(a, Complex):
1511-
return pyoperator(complex(a), complex(b))
1511+
return pyoperator(complex(a), float(b))
15121512
else:
15131513
return NotImplemented
15141514

0 commit comments

Comments
 (0)