Message10721

Author jsaiz
Recipients jsaiz
Date 2016-02-05.12:31:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454675515.89.0.9131192834.issue2460@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-02-05 12:31:56jsaizsetrecipients: + jsaiz
2016-02-05 12:31:55jsaizsetmessageid: <1454675515.89.0.9131192834.issue2460@psf.upfronthosting.co.za>
2016-02-05 12:31:55jsaizlinkissue2460 messages
2016-02-05 12:31:54jsaizcreate