Hi,
I have this C code which does complex number arithmetic. When I try to
write a similar file for C++, it says that "creal’ was not declared in
this scope". Can anyone give a better idea to write it using
"complex.h", other than using own data structures?
#include <stdio.h>
#include <complex.h>
int main(){
// double pi = 4*atan2(1);
double complex A = 32 + 24*I;
double complex B = 64 + 48*I;
double complex sum = A + B;
printf("\na is %f + %fi\n",creal(A), cimag(A));
printf("b is %f + %fi\n",creal(B), cimag(B));
printf("sum is %f + %fi\n",creal(sum), cimag(sum));
printf("sum: abs = %f , angle = %f\n", cabs(sum), carg(sum));
return(0);
}
Thanks,
Reshmi 4 4535
Reshmi wrote:
Hi,
I have this C code which does complex number arithmetic. When I try to
write a similar file for C++, it says that "creal’ was not declared in
this scope". Can anyone give a better idea to write it using
"complex.h", other than using own data structures?
#include <stdio.h>
#include <complex.h>
C++ does not include C99's _Complex type.
Use std::complex from <complex>
--
Ian Collins.
Reshmi wrote:
Hi,
I have this C code which does complex number arithmetic. When I try to
write a similar file for C++, it says that "creal? was not declared in
this scope". Can anyone give a better idea to write it using
"complex.h", other than using own data structures?
#include <stdio.h>
#include <complex.h>
int main(){
// double pi = 4*atan2(1);
double complex A = 32 + 24*I;
double complex B = 64 + 48*I;
double complex sum = A + B;
printf("\na is %f + %fi\n",creal(A), cimag(A));
printf("b is %f + %fi\n",creal(B), cimag(B));
printf("sum is %f + %fi\n",creal(sum), cimag(sum));
printf("sum: abs = %f , angle = %f\n", cabs(sum), carg(sum));
return(0);
}
#include <complex>
#include <iostream>
typedef std::complex< double double_complex;
int main ( void ) {
double_complex A ( 32, 24 );
double_complex B ( 64, 48 );
double_complex sum = A + B;
std::cout << "A is " << A << '\n';
std::cout << "B is " << B << '\n';
std::cout << "sum is " << sum << '\n';
std::cout << "sum: abs = " << std::abs( sum )
<< ", angle = " << std::arg( sum ) << '\n';
}
Best
Kai-Uwe Bux
On Sep 20, 4:57 am, Ian Collins <ian-n...@hotmail.comwrote:
Reshmi wrote:
I have this C code which does complex number arithmetic.
When I try to write a similar file for C++, it says that
"creal’ was not declared in this scope". Can anyone give a
better idea to write it using "complex.h", other than using
own data structures?
#include <stdio.h>
#include <complex.h>
C++ does not include C99's _Complex type.
Use std::complex from <complex>
Or, given his code, compile the program as C (and ask any
further questions about it in comp.lang.c, of course).
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Hi James,
This is part of a bigger function. All other files are in C++. So, I
wanted to write this function in C++ as well.
Reshmi
On Sep 20, 4:25 am, James Kanze <james.ka...@gmail.comwrote:
On Sep 20, 4:57 am, Ian Collins <ian-n...@hotmail.comwrote:
Reshmi wrote:
I have this C code which does complex number arithmetic.
When I try to write a similar file for C++, it says that
"creal’ was not declared in this scope". Can anyone give a
better idea to write it using "complex.h", other than using
own data structures?
#include <stdio.h>
#include <complex.h>
C++ does not include C99's _Complex type.
Use std::complex from <complex>
Or, given his code, compile the program as C (and ask any
further questions about it in comp.lang.c, of course).
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Schklerg |
last post by:
I have this script performing a calculation on a page on my site:
<script language="JavaScript">
function compute_weight(form)
{
var weight = form.wt.value;
var pgs = form.pgs.value;
var ppi =...
|
by: Justin Caldicott |
last post by:
Hi
There are n solutions to the nth root of any number, eg:
(-8)^(1/3) = 1 + sqrt(3)i
or -2
or 1 - sqrt(3)i
The following code:
|
by: Mike MacSween |
last post by:
S**t for brains strikes again!
Why did I do that? When I met the clients and at some point they vaguely
asked whether eventually would it be possible to have some people who could
read the data...
|
by: Matt |
last post by:
Hi all, Thank you for taking the time.
I have a database with 45 tables on it. 44 tables are linked to a main
table through a one to one relationship.
My question is, is there no way i can...
|
by: cowboyboborton |
last post by:
Looking for some help here. I've tried to solve this, but I just
can't. What I need to know is what formula to use in an excel
calculation to complete the following calculation. It's in two...
|
by: jraul |
last post by:
Suppose you have a complex number class, and you overload conversions
to double by only taking the real part. You also overload operator* to
do complex multiplication.
You then write:
...
|
by: beach.dk |
last post by:
Hi,
I'm trying to implement a simple hash algorith called rs_hash in
javascript,
but I cannot get a correct result.
In c the code looks like this:
|
by: perroe |
last post by:
Hi
I have a array of complex numbers that are stored in a simple double
array. This is done since the array is part of an wrapper for an
external C library, and the imaginary part of the first...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.
What's the best Big Number library for C? I need to...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |