Complex.Abs(Complex) 方法


获取复数的绝对值(或量值)。Gets the absolute value (or magnitude) of a complex number.

 static double Abs(System::Numerics::Complex value);
public static double Abs (System.Numerics.Complex value);
static member Abs : System.Numerics.Complex -> double
Public Shared Function Abs (value As Complex) As Double



一个复数。A complex number.


value 的绝对值。The absolute value of value.


下面的示例计算复数的绝对值,并说明它等效于 Magnitude 属性的值。The following example calculates the absolute value of a complex number and demonstrates that it is equivalent to the value of the Magnitude property.

using System;
using System.Numerics;

public class Example
   public static void Main()
      Complex complex1 = new Complex(2.0, 3.0);
      Console.WriteLine("|{0}| = {1:N2}", complex1, Complex.Abs(complex1));
      Console.WriteLine("Equal to Magnitude: {0}", 
// The example displays the following output:
//       |(2, 3)| = 3.60555127546399
//       Equal to Magnitude: True
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim complex1 As New Complex(2.0, 3.0)
      Console.WriteLine("|{0}| = {1:N2}", complex1, Complex.Abs(complex1))
      Console.WriteLine("Equal to Magnitude: {0}", 
   End Sub
End Module
' The example displays the following output:
'       |(2, 3)| = 3.61
'       Equal to Magnitude: True


复数的绝对值等效于它的 Magnitude 属性。The absolute value of a complex number is equivalent to its Magnitude property. 实数 a + bi 的绝对值计算如下:The absolute value of a real number a + bi is calculated as follows:

  • 如果 b = 0,则结果为0。If b = 0, the result is 0.

  • 如果 > b,则结果为 *Math.Sqrt(1 + b2/a2)。If a > b, the result is a *Math.Sqrt(1 + b2/a2).

  • 如果 b > a,则结果为 b * Math.Sqrt(1 + a2/b2)。If b > a, the result is b * Math.Sqrt(1 + a2/b2).

如果绝对值的计算导致溢出,则该方法将返回 Double.PositiveInfinityDouble.NegativeInfinityIf the calculation of the absolute value results in an overflow, the method returns either Double.PositiveInfinity or Double.NegativeInfinity. 如果 RealImaginary 属性为 Double.NaN,而另一个属性既不是 Double.PositiveInfinity 也不 Double.NegativeInfinity,则该方法将返回 Double.NaNIf either the Real or Imaginary property is Double.NaN and the other property is neither Double.PositiveInfinity nor Double.NegativeInfinity, the method returns Double.NaN.