complex
Creates complex numbers.
Defined in header <complex.h>
Syntax
#include <complex.h>
complex complex(double real, double imag);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
Creates a complex number out of the given real and imaginary parts. The imaginary part is taken to be 0 if imag is omitted.
complex is the constructor for the C++ class complex, which is defined in complex.h. Other applicable functions (listed under See also below) are also defined in complex.h. Some of these are overloaded versions of C library functions declared in math.h. C++ is required for the complex versions.
If you don't want to program in C++, but instead want to program in C, the only constructs available to you are struct complex and cabs, which give the absolute value of a complex number. Both of these are defined in math.h.
complex.h also overloads the operators +, -, *, /, +=, -=, *=, /=, =, ==, and !=. These operators give complex arithmetic in the usual sense. You can freely mix complex numbers in expressions with ints, doubles, and other numeric types. The operators « and » are overloaded for stream input and output of complex numbers, as they are for other data types in iostream.h.
Return value
The complex number with the given real and imaginary parts.
See also
Example
#include <iostream.h>
#include <complex.h>
int main(void)
{
double X - 3.1, y = 4.2;
complex z = complex(x,y);
cout << z = " << z « "\n";
cout << has real part = " << real(z) << "\n";
cout « and imaginary real part - " << imag(z) << "\n";
cout << "z has complex conjugate = " << con](z) << "\n";
return (
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/complex.h/complex/
· short form /3.1/complex/