delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/27/22:48:20

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: complex numbers, correct ??
Message-ID: <Pine.SGI.3.91.970827160403.12574A-100000@atmosp.physics.utoronto.ca>
Nntp-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
Organization: University of Toronto - Dept. of Physics
In-Reply-To: <5tsl8i$ce$1@news.IAEhv.nl>
Date: Wed, 27 Aug 1997 20:07:00 GMT
References: <5tsl8i$ce$1 AT news DOT IAEhv DOT nl>
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019