3.4 Arithmetic Operations on Complex Numbers (.NET, C#, CSharp, VB, Visual Basic, F#)
NMath provides overloaded arithmetic operators for complex numbers with their conventional meanings for those .NET languages that support them, and equivalent named methods for those that do not. Table 4 lists the equivalent operators and methods.
Operator |
Equivalent Named Method |
+ |
Add() |
- |
Subtract() |
* |
Multiply() |
/ |
Divide() |
Unary - |
Negate() |
All binary operators and equivalent named methods work either with two complex numbers, or with a complex number and a real value. For example, this C# code uses the overloaded operators:
Code Example – C# complex numbers
var c1 = new DoubleComplex( 3.2, 1.0 );
var c2 = new DoubleComplex( -11.002, -6.57 );
DoubleComplex c3 = c1 * c2;
c3 = (c1 / 3.5) - c2;
This Visual Basic code uses the equivalent named methods:
Code Example – VB complex numbers
Dim C1 As New DoubleComplex(3.2, 1.0)
Dim C2 As New DoubleComplex(-11.002, -6.57)
Dim C3 = DoubleComplex.Multiply(C1, C2)
C3 = DoubleComplex.Subtract(DoubleComplex.Divide(C1, 3.5), C2)