This section describes how to construct instances of FloatComplex and DoubleComplex.
You can construct complex number objects from a pair of numeric values representing the real and imaginary parts. If only a single value is passed, it is assumed to be the real part, and the imaginary part is set to 0.0. For example:
FloatComplex c = new FloatComplex( 1.3, 4.5 ); // 1.3 + 4.5i DoubleComplex c = new DoubleComplex( 6.5 ); // 6.5 + 0.0i
The static FromPolar() function constructs a complex number with a given magnitude and phase angle:
DoubleComplex c = DoubleComplex.FromPolar( 2 * Math.Sqrt(2), Math.PI/4 ); // c = 2.0 + 2.0i
You can also construct complex number types from a string representation of the form (real,imag). The parentheses are optional, and whitespace is ignored. Again, if only one value is supplied, it is assumed to be the real part. For instance, these are valid strings:
4.2,-5.1 (4.2,-5.1) 4.2
4.2 - 5.1i 4.2 - 5.1
string s = "(1.1, -3.23)"; DoubleComplex c = new DoubleComplex( s );
The static Parse() method performs the same function:
string s = "(1.1, -3.23)"; DoubleComplex c = DoubleComplex.Parse( s );
NOTE- Note that you cannot use parentheses to represent negative numbers, as is done in some financial formats, when parsing complex number strings.
Conversely, the overridden ToString() member function returns a string representation of complex number:
FloatComplex c = new FloatComplex( 7.61, -1.2 ); Console.WriteLine( c.ToString() ); // prints "(7.61,-1.2)"
A variant of the ToString() method also accepts a standard .NET numeric format string. For example, the format string "E" indicates exponential (scientific) notion.
The implicit conversion operators for the complex number classes are shown in Figure 1. An arrow indicates implicit promotion.
|