Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #110281
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Unexpected NANs in complex arithmetic |
| Date | 2016-06-22 12:57 +1000 |
| Message-ID | <mailman.23.1466564278.11516.python-list@python.org> (permalink) |
| References | <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmrHcHM9RT5jZ=zAJ-bPavTQ12Mnp4HpLB4KwQsrSZtLTw@mail.gmail.com> |
On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano <steve@pearwood.info> 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*z # should be the same as -z
> (-inf+nanj)
>
>
> And even more strange:
>
> py> 1*z
> (inf+nanj)
>
>
>
> Is this the right behaviour? If so, what's the justification for it?
I've no idea, so I Googled StackExchange [1] and found this:
http://math.stackexchange.com/questions/585766/what-is-infinity-in-complex-plane-and-what-are-operation-with-infinity-extended
Notably this:
"""
To some extent, +∞+∞ and −∞−∞ also play this role on the real axis:
they are not a destination, they are road signs that tell us to go in
a certain direction and never stop.
"""
So when your real part is float("inf"), what you're really saying is
"Go as far as you possibly can in the positive direction, then keep
going (because you haven't run out of numbers yet), and tell me, what
is 1*z tending towards?". Infinity isn't a number, and the imaginary
part of your complex number isn't really a factor in figuring out
where you're likely to end up with your multiplication. I guess that's
a justification for it coming out as NaN.
ChrisA
[1] http://www.theallium.com/engineering/computer-programming-to-be-officially-renamed-googling-stackoverflow/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unexpected NANs in complex arithmetic Steven D'Aprano <steve@pearwood.info> - 2016-06-22 12:48 +1000
Re: Unexpected NANs in complex arithmetic Chris Angelico <rosuav@gmail.com> - 2016-06-22 12:57 +1000
Re: Unexpected NANs in complex arithmetic Dan Sommers <dan@tombstonezero.net> - 2016-06-22 03:54 +0000
Re: Unexpected NANs in complex arithmetic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-22 16:17 +1000
Re: Unexpected NANs in complex arithmetic Paul Rubin <no.email@nospam.invalid> - 2016-06-21 23:25 -0700
Re: Unexpected NANs in complex arithmetic Chris Angelico <rosuav@gmail.com> - 2016-06-22 16:30 +1000
Re: Unexpected NANs in complex arithmetic Dan Sommers <dan@tombstonezero.net> - 2016-06-22 22:54 +0000
Re: Unexpected NANs in complex arithmetic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-22 16:58 +1000
Re: Unexpected NANs in complex arithmetic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-22 17:05 +1000
Re: Unexpected NANs in complex arithmetic Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-06-22 09:14 +0200
Re: Unexpected NANs in complex arithmetic Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-06-22 10:18 +0100
csiph-web