Message253290
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 :) |
|
Date |
User |
Action |
Args |
2015-10-21 15:19:15 | Francesco Biscani | set | recipients:
+ Francesco Biscani, lemburg, mark.dickinson, eric.smith, stutzbach, ezio.melotti, steven.daprano, Saksham Agrawal |
2015-10-21 15:19:15 | Francesco Biscani | set | messageid: <1445440755.15.0.812236011886.issue25453@psf.upfronthosting.co.za> |
2015-10-21 15:19:15 | Francesco Biscani | link | issue25453 messages |
2015-10-21 15:19:14 | Francesco Biscani | create | |
|