Skip to content

Commit 7353470

Browse files
committed
+ specify more properties for * and /
1 parent e8c8803 commit 7353470

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

peps/pep-0812.rst

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ complex values for :class:`ast.Constant` node type, e.g.
279279
Complex Arithmetic
280280
------------------
281281

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

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

365-
The ``*`` and ``/`` operators satisfy the following infinity properties for
366-
all real, imaginary, and complex operands:
364+
-
365+
.. code::
366+
367+
(z * w).conjugate() == z.conjugate() * w.conjugate()
368+
z * w = w * z
369+
(-z) * w = -(z * w)
367370
368371
- if one operand is an infinity and the other operand is a nonzero finite
369-
number or an infinity, then the result of the ``*`` operator is an infinity;
372+
number or an infinity, then the result is an infinity.
373+
374+
For division:
375+
376+
- with a nonzero right operand
377+
378+
.. code::
379+
380+
(z / w).conjugate() == z.conjugate() / w.conjugate()
381+
(-z) / w = -(z / w)
382+
z / (-w) = -(z / w)
370383
371384
- if the first operand is an infinity and the second operand is a finite
372-
number, then the result of the ``/`` operator is an infinity;
385+
number, then the result is an infinity;
373386

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

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

380393

381394
New C API
@@ -653,8 +666,8 @@ Footnotes
653666
654667
Other variants include using a fused multiply-add (FMA) instruction.
655668
656-
.. [8] Its easy to smash this property, as shows the `following algorithm
657-
<https://www.mjr19.org.uk/IT/IEEE_complex.html>`_:
669+
.. [8] Its easy to smash such properties, e.g. the commutativity, as shows the
670+
`following algorithm <https://www.mjr19.org.uk/IT/IEEE_complex.html>`_:
658671
659672
.. code:: python
660673

0 commit comments

Comments
 (0)