One way to define a complex(w) param or const is
param b = 10.5 + 6.23i;
But that only works if one is using 64-bit floating point. For those of us who try and avoid the double precision sledgehammer and use 32-bit floating point or those who want to soon use real(16) floating point arithmetic and at some stage in the future real(128), it gets messier.
param b0 = (10.5 + 6.23i):complex(64);
param b1 = 10.5:real(16) + (6.23i):imag(16);
param b2 = (10.5 + 6.23i):complex(256);
And where one is using identifiers, the use of the imaginary unit i is not feasible
Yes, you can use a coercion like
const c0 = (x, y):complex(64);
But that won't work with a param. And when you want to make that generic:
const c1 = (x, y):complex(numBits(x.type)*2));
This is really messy, ugly, unreadable, and confusing. You get the drift.
Also, at one stage @bradcray mentioned there were some issues with a type.
And that is a bit weird to people trying to port existing C/C++ or Fortran code which has loads of CMPLX, CMPLXF, and CMPLX* in C, cmplx() and dcmplx() and other things in Fortran, and a plethora of ways in C++.
Consider
inline proc cmplx(param x : real(?w), param y : real(w)) param
{
return x + y:imag(w);
}
inline proc cmplx(const x : real(?w), const y : real(w)) const
{
return x + y:imag(w);
}
inline proc cmplx(param x : real(?w), param y : imag(w)) param
{
return x + y;
}
inline proc cmplx(const x : real(?w), const y : imag(w)) const
{
return x + y;
}
inline proc cmplx(param x : imag(?w), param y : real(w)) param
{
compilerWarning("cmplx: mismatch ordering of param arguments");
return y + x;
}
inline proc cmplx(const x : imag(?w), const y : real(w)) const
{
compilerWarning("cmplx: mismatch ordering of const arguments");
return y + x;
}
inline proc cmplx(param x : real(?w)) param
{
return x + 0:imag(w);
}
inline proc cmplx(const x : real(?w)) const
{
return x + 0:imag(w);
}
inline proc cmplx(param y : imag(?w)) param
{
return 0:real(w) + y;
}
inline proc cmplx(const y : imag(?w)) const
{
return 0:real(w) + y;
}
No need to remember types, param and const data are handled consistency. Easy to read. Low overhead. You can even have an extra overlead to catch the case of where the imaginary and real components have different precisions.