TCplx is a struct representing a double-precision complex number. It has no public constructor.
Creating complex values:
Use the factory function Cplx(re, im) from Math387:
using Dew.Math;
using Dew.Math.Units;
// Option 1: qualified call
TCplx z = Math387.Cplx(3.0, 4.0); // 3 + 4i
// Option 2: with 'using static' for unqualified calls
// using static Dew.Math.Units.Math387;
TCplx z = Cplx(3.0, 4.0); // 3 + 4i
// Single-precision variant (returns TSCplx)
TSCplx zs = Math387.CplxSingle(3.0f, 4.0f);
Accessing real and imaginary parts:
TCplx z = Cplx(3.0, 4.0);
double re = z.Re; // 3.0
double im = z.Im; // 4.0
Predefined constants (in Math387):
| Constant | Value | Description |
|---|---|---|
C_I | 0 + 1i | Imaginary unit |
C_I_SINGLE | 0 + 1i (single) | Single-precision imaginary unit |
CINF | complex infinity | Complex version of INF |
CNAN | complex NaN | Complex version of NAN |
Complex vector operations:
Vectors can hold complex data. Use ExtendToComplex() to convert a real vector to complex, or pass complex scalars to arithmetic methods:
var v = new Vector();
v.Size(10, false, true);
v.SetVal(1.0);
v.ExtendToComplex(); // now complex: each element is 1+0i
v.Mul(Cplx(0, 1.0)); // multiply by i: each element becomes 0+1i
TCplx sum = Cplx(0, 0);
v.Sum(out sum); // complex sum
Overload selection: Methods accepting scalar arguments (Add, Mul, Sub, etc.) have both Double and TCplx overloads. The compiler selects based on the argument type — pass Cplx(re, im) for complex operations, or a plain double for real operations.
Common mistake: Do not use new TCplx(...) or default(TCplx) — always use Cplx(re, im).