Complex.Add Method

Definition

Adds a specified number to another specified number, where at least one of them is a complex number, and the other could be a double-precision real number.

Overloads

Add(Double, Complex)

Adds a double-precision real number to a complex number and returns the result.

Add(Complex, Double)

Adds a complex number to a double-precision real number and returns the result.

Add(Complex, Complex)

Adds two complex numbers and returns the result.

Examples

The following example illustrates addition with complex numbers.

C#
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex[] values= { new Complex(12.3, -1.4),
                          new Complex(-6.2, 3.1),
                          new Complex(8.9, 1.5) };
      foreach (var c1 in values)
         foreach (var c2 in values)
            Console.WriteLine("{0} + {1} = {2}", c1, c2,
                              Complex.Add(c1, c2));
   }
}
// The example displays the following output:
//       (12.3, -1.4) + (12.3, -1.4) = (24.6, -2.8)
//       (12.3, -1.4) + (-6.2, 3.1) = (6.1, 1.7)
//       (12.3, -1.4) + (8.9, 1.5) = (21.2, 0.1)
//       (-6.2, 3.1) + (12.3, -1.4) = (6.1, 1.7)
//       (-6.2, 3.1) + (-6.2, 3.1) = (-12.4, 6.2)
//       (-6.2, 3.1) + (8.9, 1.5) = (2.7, 4.6)
//       (8.9, 1.5) + (12.3, -1.4) = (21.2, 0.1)
//       (8.9, 1.5) + (-6.2, 3.1) = (2.7, 4.6)
//       (8.9, 1.5) + (8.9, 1.5) = (17.8, 3)

Remarks

The Add methods allow performing addition operations that involve complex numbers.

If the method call results in an overflow in either the real or imaginary component, the value of the component is either Double.PositiveInfinity or Double.NegativeInfinity.

Languages that don't support custom operators can use the Add method to perform addition with complex numbers.

The Add methods that receive one double are more efficient than the methods that receive two complex numbers.

Add(Double, Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

Adds a double-precision real number to a complex number and returns the result.

C#
public static System.Numerics.Complex Add(double left, System.Numerics.Complex right);

Parameters

left
Double

The double-precision real value to add.

right
Complex

The complex value to add.

Returns

The sum of left and right.

Remarks

The addition of a real number (which can be regarded as the complex number a + 0i) and a complex number (c + di) takes the following form:

(a+c)+di

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10

Add(Complex, Double)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

Adds a complex number to a double-precision real number and returns the result.

C#
public static System.Numerics.Complex Add(System.Numerics.Complex left, double right);

Parameters

left
Complex

The complex value to add.

right
Double

The double-precision real value to add.

Returns

The sum of left and right.

Remarks

The addition of a complex number (a + bi) and a real number (which can be regarded as the complex number c + 0i) takes the following form:

(a+c)+bi

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10

Add(Complex, Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

Adds two complex numbers and returns the result.

C#
public static System.Numerics.Complex Add(System.Numerics.Complex left, System.Numerics.Complex right);

Parameters

left
Complex

The first complex number to add.

right
Complex

The second complex number to add.

Returns

The sum of left and right.

Remarks

The addition of a complex number, a + bi, and a second complex number, c + di, takes the following form:

(a+c)+(b+d)i

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0