Implementing ComplexArray class.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing ComplexArray class.

Joseph Wang-2
Looking over Numerical Recipes in C++, they suggest implementing a list of N
complex numbers as an array of 2*N floats because they argue that you
maintain control of how the complex number calculations are implemented.

I'm thinking about creating a ComplexArray class that initially would use this
implementation but like all classes should have interfaces that are generic
enough so that the underlying implementation can be changed.

Thoughts?



Reply | Threaded
Open this post in threaded view
|

Re: Implementing ComplexArray class.

Luigi Ballabio
On Sun, 2006-10-01 at 18:44 -0500, Joseph Wang wrote:
> Looking over Numerical Recipes in C++, they suggest implementing a list of N
> complex numbers as an array of 2*N floats because they argue that you
> maintain control of how the complex number calculations are implemented.

That pretty much defeats the purpose of having a std::complex class in
the standard library, doesn't it?  It's like arguing that one should
implement his own containers to maintain control.

Mark's suggestion of using valarray and complex didn't sound bad to me.

Later,
        Luigi


----------------------------------------

Dealing with failure is easy: work hard to improve. Success is also
easy to handle: you've solved the wrong problem. Work hard to improve.
-- Alan Perlis




Reply | Threaded
Open this post in threaded view
|

Re: Implementing ComplexArray class.

Joseph Wang-2
在 Monday 02 October 2006 03:31,Luigi Ballabio 写道:
> On Sun, 2006-10-01 at 18:44 -0500, Joseph Wang wrote:
> > Looking over Numerical Recipes in C++, they suggest implementing a list
> > of N complex numbers as an array of 2*N floats because they argue that
> > you maintain control of how the complex number calculations are
> > implemented.
>
> That pretty much defeats the purpose of having a std::complex class in
> the standard library, doesn't it?  It's like arguing that one should
> implement his own containers to maintain control.

That was my first reaction.

Any objections to creating an implementation agnostic ComplexArray class that
using valarray and complex?  The reason for creating a separate class is that
I'd like to have a nice interface that interoperates with the Array class.