Mail Archives: djgpp/1998/10/29/03:15:24
Won-Seok Lee wrote:
>
> $)CDear Sir:
>
> I am professionally interested in complex-number manipulation.
> Until now, I have used Turbo C 3.0 for the complex-number calculation,
> but it has memory limitation in allocating an array.
> So, recently, I challenge the calculation on DJGPP.
> But I have a problem.
> I want the following program to be executed, but this program cannot
> be compiled. The filename is 'test.cc.'
> Please advise me which part should be modified for 'Compile' and
> 'Execution.'
>
> #include <stdio.h>
> #include <math.h>
> #include <complex.h>
>
> complex a ;
>
> int main( void ) {
> a = complex( 1. , 0. ) ;
> printf( "%.5e\n" , real( a ) ) ;
> return 0 ;
> }
A C++ solution
#include <stdio.h>
#include <math.h>
#include <complex>
complex<double> a; // or double_complex a;
int main(void)
{
a = complex<double>(1., 0.);
printf("%.5e\n", real(a));
return 0;
}
And a C solution
#include <stdio.h>
#include <math.h>
__complex__ double a;
int main(void)
{
a = 1.; /* or a = 1. + 0.i; */
printf("%.5e\n", __real__ a);
return 0;
}
--
Martin Ambuhl (mambuhl AT earthlink DOT net)
Note: mambuhl AT tiac DOT net will soon be inactive
- Raw text -