NMath User's Guide

TOC |  Previous |  Next |  Index

3.4 Arithmetic Operations on Complex Numbers (.NET, C#, CSharp, Visual Basic, VB.NET)

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 2 lists the equivalent operators and methods.

Table 2 - Arithmetic operators
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:

DoubleComplex c1 = new DoubleComplex( 3.2, 1.0 );
DoubleComplex c2 = new DoubleComplex( -11.002, -6.57 );
DoubleComplex c3 = c1 * c2;
c3 = (c1 / 3.5) - c2;

This Visual Basic.NET code uses the equivalent named methods:

Dim c1 As New DoubleComplex( 3.2, 1.0 )
Dim c2 As New DoubleComplex( -11.002, -6.57 )
Dim c3 As DoubleComplex = DoubleComplex.Multiply( c1, c2 )
c3 = DoubleComplex.Subtract( DoubleComplex.Divide( c1, 3.5 ), c2 )

TOC |  Previous |  Next |  Index