Complex.Equals 메서드

정의

두 복소수가 같은지 여부를 나타내는 값을 반환합니다.

오버로드

Equals(Object)

현재 인스턴스와 지정된 개체의 값이 같은지를 나타내는 값을 반환합니다.

Equals(Complex)

현재 인스턴스와 지정된 복소수의 값이 같은지 여부를 나타내는 값을 반환합니다.

Equals(Object)

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

현재 인스턴스와 지정된 개체의 값이 같은지를 나타내는 값을 반환합니다.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

매개 변수

obj
Object

비교할 개체입니다.

반환

obj 매개 변수가 Complex 개체이거나 Complex 개체로 암시적 변환이 가능한 형식이고 해당 값이 현재 Complex 개체의 값과 같으면 true이고, 그렇지 않으면 false입니다.

설명

두 개의 복소수는 실제 부분이 동일하고 허수 부분이 같으면 동일합니다. 메서드는 Equals(Object) 다음 식과 동일합니다.

return this.Real.Equals(((Complex) value).Real) &&
       this.Imaginary.Equals(((Complex) value).Imaginary);
Return Me.Real.Equals(CType(value, Complex).Real) AndAlso 
       Me.Imaginary.Equals(CType(value, Complex).Imaginary)

매개 변수가 obj 개체가 아니지만 Complex 암시적 변환이 정의된 Equals(Object) 데이터 형식인 경우 메서드는 실제 부분이 값 obj 과 같고 가상 부분이 비교를 수행하기 전에 0과 같은 개체로 변환 objComplex 합니다. 다음 예제에서는 복소수와 배정밀도 부동 소수점 값이 같은 것을 확인하여 이를 보여 줍니다.

double n1 = 16.33;
System.Numerics.Complex c1 =
       new System.Numerics.Complex(16.33, 0);
Console.WriteLine(c1.Equals(n1));               // Returns true.
Dim n1 As Double = 16.33
Dim c1 As New System.Numerics.Complex(16.33, 0)
Console.WriteLine(c1.Equals(n1))                ' Returns True.

호출자 참고

Equals(Complex) 동일한 두 값은 실제 구성 요소와 가상 구성 요소의 정밀도가 다르기 때문에 같지 않은 것으로 간주될 수 있으므로 메서드를 주의해서 사용합니다. 비교를 수행하기 전에 를 로 변환 Double 해야 하는 경우 obj 문제를 강조할 수 있습니다. 다음 예제에서는 실제 구성 요소가 해당 Single 값이 있는 값과 같은 Single 것으로 보이는 복소수를 비교합니다. 출력에서와 같이 같음 비교는 를 반환합니다 False.

using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      float n1 = 1.430718e-12f;
      Complex c1 = new Complex(1.430718e-12, 0);
      Console.WriteLine("{0} = {1}: {2}", c1, n1, c1.Equals(n1));
   }
}
// The example displays the following output:
//       (1.430718E-12, 0) = 1.430718E-12: False
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim n1 As Single = 1.430718e-12
      Dim c1 As New Complex(1.430718e-12, 0)
      Console.WriteLine("{0} = {1}: {2}", c1, n1, c1.Equals(n1))
   End Sub
End Module
' The example displays the following output:
'       (1.430718E-12, 0) = 1.430718E-12: False

한 가지 권장되는 방법은 같음 값을 비교하는 대신 두 값(예: 값의 실제 구성 요소와 허수 구성 요소 중 하나의 .01%)에서 허용되는 차이 여백을 정의하는 것입니다. 두 값 간의 차이의 절대값이 해당 여백보다 작거나 같으면 정밀도 차이로 인해 차이가 발생할 수 있으므로 값이 같을 가능성이 높습니다. 다음 예제에서는 이 기술을 사용하여 이전 코드 예제에서 같지 않은 것으로 확인된 두 값을 비교합니다. 이제 동등하다는 것을 알게 되었습니다.

using System.Numerics;

public class Example
{
   public static void Main()
   {
      float n1 = 1.430718e-12f;
      Complex c1 = new Complex(1.430718e-12, 0);
      double difference = .0001;

      // Compare the values
      bool result = (Math.Abs(c1.Real - n1) <= c1.Real * difference) &
                    c1.Imaginary == 0;
      Console.WriteLine("{0} = {1}: {2}", c1, n1, result);
   }
}
// The example displays the following output:
//       (1.430718E-12, 0) = 1.430718E-12: True
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim n1 As Single = 1.430718e-12
      Dim c1 As New Complex(1.430718e-12, 0)
      Dim difference As Double = .0001
      
      ' Compare the values
      Dim result As Boolean = (Math.Abs(c1.Real - n1) <= c1.Real * difference) And
                              c1.Imaginary = 0
      Console.WriteLine("{0} = {1}: {2}", c1, n1, result)       
   End Sub
End Module
' The example displays the following output:
'       (1.430718E-12, 0) = 1.430718E-12: True

적용 대상

Equals(Complex)

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

현재 인스턴스와 지정된 복소수의 값이 같은지 여부를 나타내는 값을 반환합니다.

public:
 virtual bool Equals(System::Numerics::Complex value);
public bool Equals (System.Numerics.Complex value);
override this.Equals : System.Numerics.Complex -> bool
Public Function Equals (value As Complex) As Boolean

매개 변수

value
Complex

비교할 복소수입니다.

반환

이 복소수와 value가 동일한 값을 가지면 true이고, 그렇지 않으면 false입니다.

구현

설명

메서드는 Equals(Complex) 구조체에 IEquatable<T> 대한 구현을 Complex 제공합니다. 매개 변수를 복소수로 변환할 필요가 없으므로 메서드보다 Equals(Object) 약간 더 잘 수행됩니다.

두 개의 복소수는 실제 부분이 동일하고 허수 부분이 같으면 동일합니다. 메서드는 Equals(Complex) 다음 식과 동일합니다.

return this.Real.Equals(value) && this.Imaginary.Equals(value);
Return Me.Real.Equals(value.Real) AndAlso Me.Imaginary.Equals(value.Imaginary)

호출자 참고

Equals(Complex) 동일한 두 값은 실제 구성 요소와 가상 구성 요소의 정밀도가 다르기 때문에 같지 않은 것으로 간주될 수 있으므로 메서드를 주의해서 사용합니다. 다음 예제에서는 및 (10/3, 1/7)(3.33333, 0.142857) 같지 않다고 보고합니다.

System.Numerics.Complex c1 = new System.Numerics.Complex(3.33333, .142857);
System.Numerics.Complex c2 = new System.Numerics.Complex(10/3.0, 1.0/7);
Console.WriteLine("{0} = {1}: {2}", c1, c2, c1.Equals(c2));
// The example displays the following output:
//    (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): False
Dim c1 As New System.Numerics.Complex(3.33333, .142857)
Dim c2 As New System.Numerics.Complex(10/3, 1/7)
Console.WriteLine("{0} = {1}: {2}", c1, c2, c1.Equals(c2))       
' The example displays the following output:
'    (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): False

한 가지 권장되는 방법은 같음 값을 비교하는 대신 두 값(예: 값의 실제 구성 요소와 허수 구성 요소 중 하나의 .01%)에서 허용되는 차이 여백을 정의하는 것입니다. 두 값 간의 차이의 절대값이 해당 여백보다 작거나 같으면 정밀도 차이로 인해 차이가 발생할 수 있으므로 값이 같을 가능성이 높습니다. 다음 예제에서는 이 기술을 사용하여 이전 코드 예제에서 같지 않은 것으로 확인된 두 개의 복합 값을 비교합니다. 두 복소수가 같은 것을 찾습니다.

System.Numerics.Complex c1 = new System.Numerics.Complex(3.33333, .142857);
System.Numerics.Complex c2 = new System.Numerics.Complex(10/3.0, 1.0/7);
double difference = .0001;

// Compare the values
bool result = (Math.Abs(c1.Real - c2.Real) <= c1.Real * difference) &
              (Math.Abs(c1.Imaginary - c2.Imaginary) <= c1.Imaginary * difference);
Console.WriteLine("{0} = {1}: {2}", c1, c2, result);
// The example displays the following output:
//    (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): True
Dim c1 As New System.Numerics.Complex(3.33333, .142857)
Dim c2 As New System.Numerics.Complex(10/3.0, 1.0/7)
Dim difference As Double = .0001

' Compare the values
Dim result As Boolean = (Math.Abs(c1.Real - c2.Real) <= c1.Real * difference) And
                        (Math.Abs(c1.Imaginary - c2.Imaginary) <= c1.Imaginary * difference)
Console.WriteLine("{0} = {1}: {2}", c1, c2, result)       
' The example displays the following output:
'    (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): True

추가 정보

적용 대상