Taipei Forcing Club

Computer science and contract bridge

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. :(

Author: Chen-Pang He

I’m Chen-Pang He (何震邦), M.D., Taipei Medical University. I’m a compiler engineer skilled in calculus and linear algebra. I’m also a bridge director in Taiwan.