[cfe-dev] [libc++] std::polar(rho, theta) bogus for theta < 0?

Luc Bourhis luc_j_bourhis at mac.com
Thu Nov 14 10:40:59 PST 2013


Hi,

polar(rho, theta) returns (NaN, NaN) if rho < 0. The code responsible for that behaviour is in the first two lines of the body of polar:

    if (isnan(__rho) || signbit(__rho))
        return complex<_Tp>(_Tp(NAN), _Tp(NAN));

libstdc++, on the contrary, returns (rho*cos(theta), rho*sin(theta)) in this case.

The standard says "Returns: the complex value corresponding to a complex number whose magnitude is rho and whose phase angle is theta."
It seems to favour libc++ choice over libstdc++ one but it is a real pain when the two major standard libraries on current platforms disagree in such a manner.
We have hit that bug hard in the Computational Crystallography Toolbox, which has to run on MacOS, Linuxes (and Windows but that's another story).

Thanks,

Luc J. Bourhis





More information about the cfe-dev mailing list