Re: Unexpected NANs in complex arithmetic

2016-06-22 Thread Dan Sommers
On Wed, 22 Jun 2016 16:30:49 +1000, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 4:17 PM, Steven D'Aprano > wrote: >> On Wednesday 22 June 2016 13:54, Dan Sommers wrote: >> >>> By the time Python returns a result for inf+3j, you're already in >>> trouble (or perhaps Python is already in troubl

Re: Unexpected NANs in complex arithmetic

2016-06-22 Thread Oscar Benjamin
On 22 June 2016 at 08:14, Antoon Pardon wrote: > Op 22-06-16 om 04:48 schreef Steven D'Aprano: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) >> py> -z >> (-inf-3j) >> >> So far,

Re: Unexpected NANs in complex arithmetic

2016-06-22 Thread Antoon Pardon
Op 22-06-16 om 04:48 schreef Steven D'Aprano: > I'm doing some arithmetic on complex numbers involving INFs, and getting > unexpected NANs. > > py> INF = float('inf') > py> z = INF + 3j > py> z > (inf+3j) > py> -z > (-inf-3j) > > So far, nothing unexpected has occurred. But: > > py> -1*z # should

Re: Unexpected NANs in complex arithmetic

2016-06-22 Thread Steven D'Aprano
On Wednesday 22 June 2016 16:58, Steven D'Aprano wrote: > But it makes no sense to me to introduce a NAN into a calculation > just because you multiply by 1, even if it includes an INF. And multiplying > by -1 should be identical to negating. Ah, not one second after I hit send, it struck me -- P

Re: Unexpected NANs in complex arithmetic

2016-06-22 Thread Steven D'Aprano
On Wednesday 22 June 2016 12:57, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano > wrote: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) >> py> -z >> (-

Re: Unexpected NANs in complex arithmetic

2016-06-21 Thread Chris Angelico
On Wed, Jun 22, 2016 at 4:17 PM, Steven D'Aprano wrote: > On Wednesday 22 June 2016 13:54, Dan Sommers wrote: > >> By the time Python returns a result for inf+3j, you're already in >> trouble (or perhaps Python is already in trouble). > > I don't see why. It is possible to do perfectly sensible ar

Re: Unexpected NANs in complex arithmetic

2016-06-21 Thread Paul Rubin
Steven D'Aprano writes: >> By the time Python returns a result for inf+3j, you're already in >> trouble (or perhaps Python is already in trouble). > I don't see why. It is possible to do perfectly sensible arithmetic on INFs. We sometimes think of the real line extended by +/- inf, or the complex

Re: Unexpected NANs in complex arithmetic

2016-06-21 Thread Steven D'Aprano
On Wednesday 22 June 2016 13:54, Dan Sommers wrote: > By the time Python returns a result for inf+3j, you're already in > trouble (or perhaps Python is already in trouble). I don't see why. It is possible to do perfectly sensible arithmetic on INFs. > A complex number has > a real part and an i

Re: Unexpected NANs in complex arithmetic

2016-06-21 Thread Dan Sommers
On Wed, 22 Jun 2016 12:57:55 +1000, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano wrote: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) [...] >> Is

Re: Unexpected NANs in complex arithmetic

2016-06-21 Thread Chris Angelico
On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano wrote: > I'm doing some arithmetic on complex numbers involving INFs, and getting > unexpected NANs. > > py> INF = float('inf') > py> z = INF + 3j > py> z > (inf+3j) > py> -z > (-inf-3j) > > So far, nothing unexpected has occurred. But: > > py> -1*