Do I have to cast double to cdouble everywhere?
Don
nospam at nospam.com
Sat Aug 7 12:53:11 PDT 2010
John Travers wrote:
> Hi,
>
> I'm investigating if D would be useful to me as a numerical programming
> language to replace my current mix of fortran and python.
Welcome! There are quite a few of us who are numerical programmers here,
and it's one of D's target areas.
>
> I'm stuck with a problem which seems odd to me:
>
> cdouble c1;
> c1 = 2.0;
>
> complains:
>
> Error: cannot implicitly convert expression (2) of type double to cdouble
>
> The only way I can find to solve this is by doing:
>
> c1 = cast(cdouble)2.0;
>
> This will drive me crazy, many numeric codes need to multiply complex numbers,
> or assign to them, with real numbers. This problem also occurs with imaginary
> numbers.
Unfortunately we had to disable implicit casts double->cdouble, because
it causes problems with function overloading.
So you need to explicitly add the imaginary part.
c1 = 2.0 + 0.0i;
More information about the Digitalmars-d-learn
mailing list