Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

james.p.leblanc james.p.leblanc at gmail.com
Wed Jul 21 08:39:29 UTC 2021


I am trying to initialize a complex dynamic array, from two 
strictly real dynamic arrays (one to be the real part, the other 
to be the imaginary part.

Here is simple sample of what I have tried:

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

import std.stdio;
import std.math;
import std.complex;

     void main(){
        auto N=2;

        double[] x,y;
        x.length = N;
        y.length = N;

        x[0] = 1.1;
        x[1] = 2.2;
        y[0] = 3.3;
        y[1] = 4.4;

        Complex!double[] z;
        z.length=N;

        z[] = complex(x[],y[]);
        // z = complex(x,y);  // also tried this, did not work
     }

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

     The compile error message is:

     rdmd post.d
     post.d(22): Error: template `std.complex.complex` cannot 
deduce function from argument types `!()(double[], double[])`, 
candidates are:
     
/home/leblanc/dmd2/linux/bin64/../../src/phobos/std/complex.d(46):        `complex(R)(const R re)`
     
/home/leblanc/dmd2/linux/bin64/../../src/phobos/std/complex.d(56):        `complex(R, I)(const R re, const I im)`
       with `R = double[],
            I = double[]`
       whose parameters have the following constraints:
       `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
     `  > is(R : double)
       - is(I : double)
     `  `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
     post.d(22):        All possible candidates are marked as 
`deprecated` or `@disable`
       Tip: not satisfied constraints are marked with `>`
     Failed: ["/home/leblanc/dmd2/linux/bin64/dmd", "-v", "-o-", 
"post.d", "-I."]

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

I understand, I could write a simple function to do this...but 
was wondering if there is some "standard" way of doing this 
already?

Thanks,
James

PS Is cdouble (and friends) really going to be deprecated??  I 
worry that the loss of the built-in complex types eventually 
might have a downside for syntax and writing.  (But, I might very 
well be wrong about this!!).







More information about the Digitalmars-d-learn mailing list