[issue25453] Arithmetics with complex infinities is inconsistent with C/C++

Francesco Biscani report at bugs.python.org
Wed Oct 21 11:19:15 EDT 2015


Francesco Biscani added the comment:

The best reference I could find so far is in the C99 standard:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

Annex G is titled "IEC 60559-compatible complex arithmetic". In G.3.1 it is written:

"""
A complex or imaginary value with at least one infinite part is regarded as an infinity (even if its other part is a NaN).
"""

Later on, in G.5.1.4, it is stated:

"""
The * and / operators satisfy the following infinity properties for all real, imaginary, and complex operands:

- 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;
- if the first operand is an infinity and the second operand is a finite number, then the result of the / operator 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;
"""

So to recap, according to these definitions:

- inf + nanj is a complex infinity,
- (inf + nanj) * (2 + 0j) should give a complex infinity (i.e., a complex number in which at least one component is inf).

I am not saying that these rules are necessarily "mathematically correct". I am aware that floating point is always a quagmire to get into, and the situation here is even more complex (eh!) than usual.

But it seems to me that Python, or CPython at least, follows a pattern of copying (or relying on) the behaviour of C for floating-point operations, and it seems like in the case of complex numbers this "rule" is broken. It certainly caught me by surprise anyway :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25453>
_______________________________________


More information about the Python-bugs-list mailing list