On Jul 16, 2006, at 12:05 PM, Bob Delaney wrote:
Since I develop RB applications on Linux from time to time, I
couldn't use
Bob Delaney's ComplexPlugin (which is a great Plugin, by the way).
For that
reason, and also for the sheer fun of it, I decided to roll my own
Complex
Class, written in RB and open source.
The Complex class overloads the standard operators (+, -, *, /, ^)
for
complex numbers, and it implements a number of mathematical functions
already available in RB (abs, sqrt, exp, log, sin, cos, tan, asin,
acos,
atan) for complex numbers. It also adds a series of new functions
(conj,
inv, norm, Cot, Sec, Cosec, Sinh, Cosh, Tanh, Asinh, Acosh, Atanh)
for
complex numbers.
Any feedback and/or contributions will be appreciated.
The project archive can be found at the following URL:
http://www.the-meiers.org/opensource/
Thanks,
Roger
Roger,
I note that you use the standard code for a complex multiply:
(a + i*b) * (c + i*d) = ( (a*c) - (b*d) + i*((a*d) + (b*c)) )
This requires 4 multiplications and 2 additions. Since a
multiplication of doubles takes considerably longer than does an
addition, you might want to consider using the following:
x + i*y = (a + i*b) * (c + i*d)
ac = a*c
bd = b*d
y = (a + b)*(c + d) - ac - bd
x = ac - bd
which requires 3 multiplications and 5 additions.
Bob
I just did some timings and it appears as if the multiply is faster
on my G4 but the difference is quite small.
I would not recommend the "fast" method as it performs more total
operations (8 versus 6) and is likely to have greater rounding error
due to canceling out the ac and bd terms in the y term.
If you are concerned about speed, the best thing to do is probably to
benchmark the two methods on a variety of platforms.
Cheers,
Malcolm Smith
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>