delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/29/20:31:49

From: swarsmatt AT aol DOT com (SWars Matt)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: complex numbers, correct ??
Date: 27 Aug 1997 21:12:48 GMT
Lines: 24
Message-ID: <19970827211201.RAA06687@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Organization: AOL http://www.aol.com
References: <5tsl8i$ce$1 AT news DOT IAEhv DOT nl>
SnewsLanguage: English
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jos Bergervoet wrote:

>  complex    a, b, c;
>    a = complex(23.4, 26.9);
>    b = (a+2)/(a+3);
>    printf( "Hello: result = (%10.4g,%10.4g)\n", b );

I haven't used the complex number class, but I think I know a few of your
probelms. First of all, complex is a template, so you have to use
complex<double> or complex<float> or complex<int>, you get the idea. I
don't think printf can use complex numbers. Complex numbers are not a basic
data type in ANSI C. The << operator is probably overloaded for the class
(I don't know without checking). Check to see if a declaration like ostream
operator<<(complex) is included in the class declaration in std/complexn.h
(I think that's the file name).  Because complex numbers are a class,
printf probably doesn't have any idea what to do with them. You could
possibly write printf("%10.4g, %10.4g", b.re, b.im) to print this out. (I
think it's re and im, anyway). As it is printf is probably expecting two
variable names for floating point numbers.
Sorry that I'm not sure about all of that, but I haven't worked with the
complex number class so I'm not really sure exactly what you can do with it.



- Raw text -


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