[Bug libstdc++/12961] Problem with generic complex constructor

Yves dot Renard at gmm dot insa-tlse dot fr gcc-bugzilla@gcc.gnu.org
Mon Nov 10 06:55:00 GMT 2003


------- Additional Comments From Yves dot Renard at gmm dot insa-tlse dot fr  2003-11-10 06:54 -------
(In reply to comment #1)
> Hi. Could you please provide a small, self-contained code snippet demonstrating
> the problem?
> 
> Thanks, Paolo.
> 
> P.S. I have even tried downloading your library but grepping for 'qd_real' finds
> nothing...
QD is a library for double-double and quadruple-double you will find at the
following address:
http://www.nersc.gov/~dhb/mpdist/mpdist.html


But I think, the problem is that the template definition should be
complex(const _Tp& = _Tp(), const _Tp & = _Tp(0));
(this was the case in preceding version of the S.T.L.)
or better, there should be two constructors
One to initialize a complex with a real, or two real, with an initialization
to zero of the imaginary part:
complex(const _Tp&, const _Tp & = _Tp(0));
And one default constructor which does not initialize anything:
complex()



The problem with QD is that the default constructor does not initialize the
number to zero. Then when I declare

std::complex<qd_real> a(1);

The real part is initialized to 1 but the imaginary part is not initialized.
So a will be equal to something as (1.0 + 3.354434534i)
What is stange is that if the template definition would be applied to float,
double or long double, the problem would be the same. Fortunately, a specialization
is made. But, even for those types, I am not convince that the constructor:
complex(float = 0.0f, float = 0.0f);
is very convenient, because it implies that a complex is alway at least initialized
zero (lost of comp. time). I think that there should be two constructors also
for complex<float>, complex<double> and complex<long double> (i.e. one additional 
default constructor which does not do anything).













-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12961



More information about the Gcc-bugs mailing list