complex numbers in polar form

248 views
Skip to first unread message

Marcoen Hirschberg

unread,
Jun 21, 2012, 9:02:08 AM6/21/12
to juli...@googlegroups.com
I am experimenting a bit with complex numbers in polar form. My idea was that some functions on complex number could return their result in polar form to avoid potentially useless conversions back to cartesian form. (I haven't see any speed improvements yet)

Could you guys take a look and tell me if I'm on the right track (or if it's useless)


Thanks

Marcoen

Stefan Karpinski

unread,
Jun 21, 2012, 12:06:02 PM6/21/12
to juli...@googlegroups.com
Looks pretty good. I think one wouldn't want to have both rectangular and polar representations at the same time, honestly. What you really want is to be able to pick one or the other by changing an import (on its way) and trying the same code both ways. For some algorithms, the polar representation is going to be more efficient.

Also, the Complex128 and Complex64 types are a nasty hack to get C-struct-like layout using a bits type. What you really here is to have both rectangular and polar complex representations be immutable composites (also a planned feature) so that they can be automatically represented in a way that's compatible with C structs. Until that happens, composite types can't hope to compete because they don't have a sufficiently compact layout and force extra pointer dereferences and heap memory lookups.

Until those features happen (modules and immutable composites), I wouldn't worry too much about performance, but just work on making polar complex numbers a drop-in replacement for rectangular complex numbers to the extent possible.


Marcoen

--

Reply all
Reply to author
Forward
0 new messages