Re: Help with Complex numbers
Markus Werle <[email protected]> Wed, 4 Jan 2006 11:09:10 +0000 (UTC)
| Newsgroups | gmane.comp.lib.daixtrose.help |
|---|---|
| Message-ID | <[email protected]> |
John Fletcher <J.P.Fletcher <at> aston.ac.uk> writes:
> Happy New Year
Dito.
> I am having some success with adapting the Solver example.
>
> I want to run some cases where the variables are complex
> numbers. I have adapted the solver code to be templated and
> have defined complex as follows
>
> typedef _Complex double complex;
Have you tried std::complex<double>?
Also I think it is easier define your own data type
containing the complex, just to get sure you do not get
messed up with the beasty name lookup rules of C++ and mix up
with already define operators. But see above how to change
the definition of class Scalar to achiev the same effect.
> [...]
> When I move it to g++ 4.0.2 it will no longer compile. It says that a
> cast from double to double __complex__ is illegal and I have not
> been able to find any way to initialise a complex variable from an
> expression.
If you uise your own data type you can add a constructor
which takes an "Expr<T> const &" as argument to get along.
If an own data type is not the option you like, then you could play
FeaturesOfExpression again to provide a user-defined
conversion operator to whatever
I am not sure if this hits the point.
Could you please provide a short code snippet that already compiles
(or fails to compile?)
>
> This also throws up the fact that Daixt::Scalar has an internal type
> of double, and I think I will need a complex version of that.
You are right, Scalar was a quick hack.
This is why it is hidden in namespace Convenience.
Use your own version of Scalar:
template<typename T, typename D>
class Scalar
{
public:
typedef D Disambiguation;
typedef T NumericalType;
inline Scalar(const NumericalType& Value = NumericalType()) : Value_(Value) {}
inline NumericalType Value() const { return Value_; }
private:
NumericalType Value_;
};
And use std::complex<double> if possible.
best regards,
Markus
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click