Skip to content
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fa9c087
Initial version
skirpichev Dec 5, 2023
fea0b1d
Reserve number 812
skirpichev Oct 29, 2025
5665f85
+ format refs
skirpichev Oct 31, 2025
983e5da
+ set Sponsor & .github/CODEOWNERS
skirpichev Oct 31, 2025
d7d6f0e
cleanup: use extlinks
skirpichev Nov 1, 2025
ad7d448
+ imaginary literals and marshal
skirpichev Nov 1, 2025
369a213
+ NO latex
skirpichev Nov 1, 2025
f4c9c9c
link to Kahan paper
skirpichev Nov 1, 2025
a5bb13a
ad7d448f +1
skirpichev Nov 1, 2025
bc825bf
+ mention mpmath issue 473
skirpichev Nov 1, 2025
63140c2
Merge branch 'master' into imaginary
skirpichev Nov 2, 2025
f69e6c5
Merge branch 'master' into imaginary
skirpichev Nov 4, 2025
27a429f
Merge branch 'master' into imaginary
skirpichev Nov 5, 2025
29fef03
Apply suggestions from code review
skirpichev Nov 5, 2025
0df61c9
Merge branch 'imaginary' of github.com:skirpichev/peps into imaginary
skirpichev Nov 5, 2025
612f2af
address review: apply rest of suggestions
skirpichev Nov 5, 2025
a31d7c1
+ add another algorithm for multiplication
skirpichev Nov 6, 2025
e961ef7
fix formatting
skirpichev Nov 6, 2025
5f35d52
Update peps/pep-0812.rst
skirpichev Nov 7, 2025
b573c82
Merge branch 'main' into imaginary
skirpichev Nov 16, 2025
bf0d67f
address review: move inline footnotes 5-7
skirpichev Nov 16, 2025
27b45b9
+ expose imaginary builtin
skirpichev Nov 20, 2025
8fe6c41
+ ast
skirpichev Nov 20, 2025
e8c8803
separate section for arithmetic
skirpichev Nov 21, 2025
7353470
+ specify more properties for * and /
skirpichev Nov 21, 2025
8e12d53
footnote on complex infinity
skirpichev Nov 21, 2025
036d49c
Merge branch 'main' into imaginary
skirpichev Dec 12, 2025
ffbc299
Merge branch 'master' into imaginary
skirpichev Dec 19, 2025
252c83d
Simplify imaginary() constructor
skirpichev Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
+ specify more properties for * and /
  • Loading branch information
skirpichev committed Nov 21, 2025
commit 73534705b4e5e9d2d5efa677c2667e86695a328d
47 changes: 30 additions & 17 deletions peps/pep-0812.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ complex values for :class:`ast.Constant` node type, e.g.
Complex Arithmetic
------------------


The tables below define unary operations, additive operators (binary ``+`` and
``-``) and multiplicative operators (``*`` and ``/``) for all possible
combinations of types (integer operand values will be implicitly converted to
Expand Down Expand Up @@ -353,29 +352,43 @@ result has imaginary type. If both operands have imaginary type, then the
result has real type. If either operand has complex type, then the result has
complex type.

This specification does not indicate how exactly the results are to be evaluated
[7]_ for complex multiplication (when *both* operands are complex numbers) and
for division when the right operand is a complex number. Though, if
the implementation of floating-point arithmetic supports the IEC 60559
floating-point standard, results of all mixed-mode operations, except for
division, are specified above unambiguously and it's also expected that
multiplication always must be commutative [8]_, and that division compute result
without undue overflow or underflow.
Results of all mixed-mode operations, except for division when the right
operand is a complex number, are unambigously defined by floating-point
arithmetic. This specification does not indicate how exactly the results are
to be evaluated [7]_ for complex multiplication (when *both* operands are
complex numbers) and for division (when the *right* operand is a complex
number). Though, the following holds.

For complex multiplication [8]_:

The ``*`` and ``/`` operators satisfy the following infinity properties for
all real, imaginary, and complex operands:
-
.. code::

(z * w).conjugate() == z.conjugate() * w.conjugate()
z * w = w * z
(-z) * w = -(z * w)

- if one operand is an infinity and the other operand is a nonzero finite
number or an infinity, then the result of the ``*`` operator is an infinity;
number or an infinity, then the result is an infinity.

For division:

- with a nonzero right operand

.. code::

(z / w).conjugate() == z.conjugate() / w.conjugate()
(-z) / w = -(z / w)
z / (-w) = -(z / w)

- if the first operand is an infinity and the second operand is a finite
number, then the result of the ``/`` operator is an infinity;
number, then the result is an infinity;

- if the first operand is a finite number and the second operand is an
infinity, then the result of the ``/`` operator is a zero;
infinity, then the result is a zero;

- if the first operand is a nonzero finite number or an infinity and the second
operand is a zero, then the result of the ``/`` operator is an infinity.
operand is a zero, then the result is an infinity.


New C API
Expand Down Expand Up @@ -653,8 +666,8 @@ Footnotes

Other variants include using a fused multiply-add (FMA) instruction.

.. [8] Its easy to smash this property, as shows the `following algorithm
<https://www.mjr19.org.uk/IT/IEEE_complex.html>`_:
.. [8] Its easy to smash such properties, e.g. the commutativity, as shows the
`following algorithm <https://www.mjr19.org.uk/IT/IEEE_complex.html>`_:

.. code:: python

Expand Down