Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #110301
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Unexpected NANs in complex arithmetic |
| Date | 2016-06-22 09:14 +0200 |
| Message-ID | <mailman.29.1466579717.11516.python-list@python.org> (permalink) |
| References | <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576A3ADA.5060000@rece.vub.ac.be> |
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 be the same as -z
> (-inf+nanj)
What I remember from complex numbers is that a multiplication
with a number that has |z| = 1, is equivallent with a rotation.
So you should be able to get the polar representation of this
"number", add in the angle of -1, being π, and convert back to
the cartesian representation.
I think seen this way, the nan part makes perfect sense.
Also the multiplication of a+bj with c+dj is (ac-bd)+(ad+bc)j
With your "numbers" this gives.
(inf*(-1) - 3*0) + (inf*0 + 3*(-1))j
Again the nan part makes perfect sense.
--
Antoon
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