[Bug libstdc++/50957] New: complex<T> ctor drops sign of zero (sometimes)
kreckel at ginac dot de
gcc-bugzilla@gcc.gnu.org
Wed Nov 2 08:24:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50957
Bug #: 50957
Summary: complex<T> ctor drops sign of zero (sometimes)
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kreckel@ginac.de
When compiling with -std=c++0x (and only then), the ctor of g++ drops the sign
of zero. (This sometimes devastates the correct choice of branch cuts in the
complex plain.) Interestingly, it doesn't happen with my mock complex class.
#include <iostream>
#include <complex>
using namespace std;
template<typename _Tp>
struct mock_complex
{
typedef _Tp value_type;
_GLIBCXX_CONSTEXPR mock_complex(const _Tp& __r = _Tp(), const _Tp& __i =
_Tp())
: _M_real(__r), _M_imag(__i) { }
const _Tp
real() const { return _M_real; }
const _Tp
imag() const { return _M_imag; }
private:
_Tp _M_real;
_Tp _M_imag;
};
int main()
{
mock_complex<double> z1(-0.0, 1.0);
cout << signbit(z1.real()) << signbit(z1.imag()) << endl; // correct: 10
complex<double> z2(-0.0, 1.0);
cout << signbit(z2.real()) << signbit(z2.imag()) << endl; // wrong: 00
}
More information about the Gcc-bugs
mailing list