Don't implement CMPLX
with +
For brevity, let’s forget that CMPLX
is a macro. The following code seems to
be a cross-platform solution.
inline double _Complex CMPLX(double x, double y)
{
return x + I * y;
}
It is not. Whether I
is complex or imaginary, I * y
evaluates to
(+0, y) when added with a real number. If x happens to
be -0, its sign is not preserved because -0 + +0 = +0.
I think we can only stick with compiler-specific constructs for now. :(