Issue2460
Created on 2016-02-05.12:31:55 by jsaiz, last changed 2016-03-14.16:41:31 by zyasoft.
msg10721 (view) |
Author: Jaime (jsaiz) |
Date: 2016-02-05.12:31:53 |
|
Considering two complex numbers (where rx is the real part, ix is the imaginary part):
a = (r1, i1)
b = (r2, i2)
The multiplication should give:
a * b = (r1 * r2 - i1 * i2, r1 * i2 + r2 * i1)
Now consider this example, which multiplies the imaginary number times inifinity:
a = 1j
b = -float('inf')
print a * b
The result should be (NaN, -Infinity), because r1 * r2 is 0 * -inf, giving a not-a-number.
This is the expected result with Jython 2.5.2:
linux> jython2.5
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1j
>>> b = -float('inf')
>>> print a * b
(NaN-Infinityj)
However, the result with Jython 2.7.0 is:
linux> jython2.7
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1j
>>> b = -float('inf')
>>> print a * b
(inf+infj)
Python gives the same result as Jython 2.5.2, which is the expected one:
linux> python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1j
>>> b = -float('inf')
>>> print a * b
(nan-infj)
The reason is that PyComplex._mul has been modified to return (inf, inf) when any component of the arguments is plus or minus infinity, I don't know the reason.
Could the initial implementation be restored?
|
msg10722 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-02-05.15:44:20 |
|
We need to look at the edge cases systematically, much like we have done in other work on complex math in 2.7.0. In general, we either conform to CPython, or attempt to compute the result more accurately.
|
msg10761 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-02-21.02:28:08 |
|
Fixed as of https://hg.python.org/jython/rev/5b0c3615b693
|
|
Date |
User |
Action |
Args |
2016-03-14 16:41:31 | zyasoft | set | status: pending -> closed |
2016-02-21 02:28:09 | zyasoft | set | status: open -> pending resolution: accepted -> fixed messages:
+ msg10761 |
2016-02-05 16:08:47 | zyasoft | set | priority: high milestone: Jython 2.7.1 |
2016-02-05 15:44:20 | zyasoft | set | assignee: zyasoft resolution: accepted messages:
+ msg10722 nosy:
+ zyasoft |
2016-02-05 12:31:55 | jsaiz | create | |
|