แก้ไข

แชร์ผ่าน


Complex.Explicit Operator

Definition

Defines an explicit conversion between a Complex object and another type.

Overloads

Explicit(UInt128 to Complex)

Explicitly converts a UInt128 value to a double-precision complex number.

Explicit(BigInteger to Complex)

Defines an explicit conversion of a BigInteger value to a complex number.

Explicit(Decimal to Complex)

Defines an explicit conversion of a Decimal value to a complex number.

Explicit(Int128 to Complex)

Explicitly converts a Int128 value to a double-precision complex number.

Explicit(UInt128 to Complex)

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

Important

This API is not CLS-compliant.

Explicitly converts a UInt128 value to a double-precision complex number.

public:
 static explicit operator System::Numerics::Complex(UInt128 value);
[System.CLSCompliant(false)]
public static explicit operator System.Numerics.Complex (UInt128 value);
[<System.CLSCompliant(false)>]
static member op_Explicit : UInt128 -> System.Numerics.Complex
Public Shared Narrowing Operator CType (value As UInt128) As Complex

Parameters

value
UInt128

The value to convert.

Returns

value converted to a double-precision complex number.

Attributes

Applies to

Explicit(BigInteger to Complex)

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

Defines an explicit conversion of a BigInteger value to a complex number.

public:
 static explicit operator System::Numerics::Complex(System::Numerics::BigInteger value);
public static explicit operator System.Numerics.Complex (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> System.Numerics.Complex
Public Shared Narrowing Operator CType (value As BigInteger) As Complex

Parameters

value
BigInteger

The value to convert to a complex number.

Returns

A complex number that has a real component equal to value and an imaginary component equal to zero.

Examples

The following example illustrates the explicit conversion of BigInteger values to Complex values.

BigInteger[] numbers= {
                 ((BigInteger) Double.MaxValue) * 2,
                 BigInteger.Parse("901345277852317852466891423"),
                 BigInteger.One };
foreach (BigInteger number in numbers)
{
  Complex c1 = (Complex) number;
   Console.WriteLine(c1);
}
// The example displays the following output:
//       (Infinity, 0)
//       (9.01345277852318E+26, 0)
//       (1, 0)
    let numbers =
        [ (bigint Double.MaxValue) * 2I
          BigInteger.Parse "901345277852317852466891423"
          BigInteger.One ]

    for number in numbers do
        let c1 = Complex(float number, 0.)
        printfn $"{number, 30}  -->  {c1}"
// The example displays the following output:
//       (Infinity, 0)
//       (9.01345277852318E+26, 0)
//       (1, 0)
Dim numbers() As BigInteger = {
                 CType(Double.MaxValue, BigInteger) * 2, 
                 BigInteger.Parse("901345277852317852466891423"), 
                 BigInteger.One } 
For Each number In numbers
  Dim c1 As System.Numerics.Complex = CType(number, 
                                    System.Numerics.Complex)
   Console.WriteLine(c1)
Next        
' The example displays the following output:
'       (Infinity, 0)
'       (9.01345277852318E+26, 0)
'       (1, 0)

Remarks

Explicit conversion operators define types that can be converted to a Complex object. Language compilers do not perform this conversion automatically because it can involve data loss. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.

The conversion of a BigInteger value to the real part of a complex number can result in a loss of precision because a Double, which is the type of the complex number's Real property, has fewer significant digits than a BigInteger.

If the conversion is unsuccessful because the BigInteger value is out of the range of the Double type, the operation does not throw an OverflowException. Instead, if value is less than MinValue, the result is a complex number that has a Real property value equal to NegativeInfinity. If value is greater than MaxValue, the result is a complex number that has a Real property value equal to PositiveInfinity.

Applies to

Explicit(Decimal to Complex)

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

Defines an explicit conversion of a Decimal value to a complex number.

public:
 static explicit operator System::Numerics::Complex(System::Decimal value);
public static explicit operator System.Numerics.Complex (decimal value);
static member op_Explicit : decimal -> System.Numerics.Complex
Public Shared Narrowing Operator CType (value As Decimal) As Complex

Parameters

value
Decimal

The value to convert to a complex number.

Returns

A complex number that has a real component equal to value and an imaginary component equal to zero.

Examples

The following example illustrates the explicit conversion of Decimal values to Complex values.

decimal[] numbers = { Decimal.MinValue, -18.35m, 0m, 1893.019m,
                      Decimal.MaxValue };
foreach (decimal number in numbers)
{
   System.Numerics.Complex c1 = (System.Numerics.Complex) number;
   Console.WriteLine("{0,30}  -->  {1}", number, c1);
}
// The example displays the following output:
//    -79228162514264337593543950335  -->  (-7.92281625142643E+28, 0)
//                            -18.35  -->  (-18.35, 0)
//                                 0  -->  (0, 0)
//                          1893.019  -->  (1893.019, 0)
//     79228162514264337593543950335  -->  (7.92281625142643E+28, 0)
    let numbers = [ Decimal.MinValue; -18.35m; 0m; 1893.019m; Decimal.MaxValue ]

    for number in numbers do
        let c1 = Complex(float number, 0.)
        printfn $"{number, 30}  -->  {c1}"

// The example displays the following output:
//    -79228162514264337593543950335  -->  (-7.92281625142643E+28, 0)
//                            -18.35  -->  (-18.35, 0)
//                                 0  -->  (0, 0)
//                          1893.019  -->  (1893.019, 0)
//     79228162514264337593543950335  -->  (7.92281625142643E+28, 0)
Dim numbers() As Decimal = { Decimal.MinValue, -18.35d, 0d, 1893.019d, 
                             Decimal.MaxValue }
For Each number In numbers
   Dim c1 As System.Numerics.Complex = CType(number, 
                                             System.Numerics.Complex)
   Console.WriteLine("{0,30}  -->  {1}", number, c1)
Next   
' The example displays the following output:
'    -79228162514264337593543950335  -->  (-7.92281625142643E+28, 0)
'                            -18.35  -->  (-18.3500003814697, 0)
'                                 0  -->  (0, 0)
'                          1893.019  -->  (1893.01904296875, 0)
'     79228162514264337593543950335  -->  (7.92281625142643E+28, 0)

Remarks

Explicit conversion operators define types that can be converted to a Complex object. Language compilers do not perform this conversion automatically because it can involve data loss. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.

The conversion of a Decimal value to the real part of a complex number can result in a loss of precision because a Double, which is the type of the complex number's Real property, has fewer significant digits than a Decimal.

Applies to

Explicit(Int128 to Complex)

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

Explicitly converts a Int128 value to a double-precision complex number.

public:
 static explicit operator System::Numerics::Complex(Int128 value);
public static explicit operator System.Numerics.Complex (Int128 value);
static member op_Explicit : Int128 -> System.Numerics.Complex
Public Shared Narrowing Operator CType (value As Int128) As Complex

Parameters

value
Int128

The value to convert.

Returns

value converted to a double-precision complex number.

Applies to