Mail Archives: djgpp/1997/08/27/22:48:20
On 25 Aug 1997, Jos Bergervoet wrote:
> I installed djgpp 2.721, read the FAQ (for v2.01) and still don't
> see why the following does not work. Other compiler have no problem
> with it. I noticed that using complex<double> in the declaration
> makes the compiler accept it, but still it computes (0,0) instead
> of ( 0.981, 0.018). Have I missed recent changes in the C++ syntax?
>
> Greetings,
> Jos Bergervoet
>
> complex a, b, c;
> a = complex(23.4, 26.9);
> b = (a+2)/(a+3);
> printf( "Hello: result = (%10.4g,%10.4g)\n", b );
printf() is a C function, not a C++ function. C knows nothing about
complex types, or any C++ class type for that matter. The g in the format
code causes it interpret b as a float. Since it isn't you get undefined
results.
Try this:
cout << "Hello: result = " << b << endl;
By the way, if the code fragment you give above works on other compilers
dump them! This would be a compiler bug.
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -