本文整理汇总了VB.NET中System.Numerics.Complex结构体的典型用法代码示例。如果您正苦于以下问题:VB.NET Complex结构体的具体用法?VB.NET Complex怎么用?VB.NET Complex使用的例子?那么恭喜您, 这里精选的结构体代码示例或许可以为您提供帮助。
在下文中一共展示了Complex结构体的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Numerics
Module Example
Public Sub Main()
' Create a complex number by calling its class constructor.
Dim c1 As New Complex(12, 6)
Console.WriteLine(c1)
' Assign a Double to a complex number.
Dim c2 As Complex = 3.14
Console.WriteLine(c2)
' Cast a Decimal to a complex number.
Dim c3 As Complex = CType(12.3d, Complex)
Console.WriteLine(c3)
' Assign the return value of a method to a Complex variable.
Dim c4 As Complex = Complex.Pow(Complex.One, -1)
Console.WriteLine(c4)
' Assign the value returned by an operator to a Complex variable.
Dim c5 As Complex = Complex.One + Complex.One
Console.WriteLine(c5)
' Instantiate a complex number from its polar coordinates.
Dim c6 As Complex = Complex.FromPolarCoordinates(10, .524)
Console.WriteLine(c6)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:30,代码来源:Complex 输出:
(12, 6)
(3.14, 0)
(12.3000001907349, 0)
(1, 0)
(2, 0)
(8.65824721882145, 5.00347430269914)
示例2: Complex
Dim value As New Complex(Double.MinValue/2, Double.MinValue/2)
Dim value2 As Complex = Complex.Exp(Complex.Log(value))
Console.WriteLine("{0} {3}{1} {3}Equal: {2}", value, value2,
value = value2,
vbCrLf)
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:5,代码来源:Complex 输出:
(-8.98846567431158E+307, -8.98846567431158E+307)
(-8.98846567431161E+307, -8.98846567431161E+307)
Equal: False
示例3: Example
' 导入命名空间
Imports System.Numerics
Module Example
Public Sub Main()
Dim c1 As Complex = New Complex(Double.MaxValue / 2, Double.MaxValue /2)
Dim c2 As Complex = c1 / Complex.Zero
Console.WriteLine(c2.ToString())
c2 = c2 * New Complex(1.5, 1.5)
Console.WriteLine(c2.ToString())
Console.WriteLine()
Dim c3 As Complex = c1 * New Complex(2.5, 3.5)
Console.WriteLine(c3.ToString())
c3 = c3 + New Complex(Double.MinValue / 2, Double.MaxValue / 2)
Console.WriteLine(c3)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:19,代码来源:Complex 输出:
(NaN, NaN)
(NaN, NaN)
(NaN, Infinity)
(NaN, Infinity)
示例4: GetFormat
' 导入命名空间
Imports System.Numerics
Public Class ComplexFormatter
Implements IFormatProvider, ICustomFormatter
Public Function GetFormat(formatType As Type) As Object _
Implements IFormatProvider.GetFormat
If formatType Is GetType(ICustomFormatter) Then
Return Me
Else
Return Nothing
End If
End Function
Public Function Format(fmt As String, arg As Object,
provider As IFormatProvider) As String _
Implements ICustomFormatter.Format
If TypeOf arg Is Complex Then
Dim c1 As Complex = DirectCast(arg, Complex)
' Check if the format string has a precision specifier.
Dim precision As Integer
Dim fmtString As String = String.Empty
If fmt.Length > 1 Then
Try
precision = Int32.Parse(fmt.Substring(1))
Catch e As FormatException
precision = 0
End Try
fmtString = "N" + precision.ToString()
End If
If fmt.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase) Then
Return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "i"
ElseIf fmt.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase) Then
Return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "j"
Else
Return c1.ToString(fmt, provider)
End If
Else
If Typeof arg Is IFormattable Then
Return DirectCast(arg, IFormattable).ToString(fmt, provider)
ElseIf arg IsNot Nothing Then
Return arg.ToString()
Else
Return String.Empty
End If
End If
End Function
End Class
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:49,代码来源:Complex
示例5: Example
Module Example
Public Sub Main()
Dim c1 As Complex = New Complex(12.1, 15.4)
Console.WriteLine("Formatting with ToString(): " +
c1.ToString())
Console.WriteLine("Formatting with ToString(format): " +
c1.ToString("N2"))
Console.WriteLine("Custom formatting with I0: " +
String.Format(New ComplexFormatter(), "{0:I0}", c1))
Console.WriteLine("Custom formatting with J3: " +
String.Format(New ComplexFormatter(), "{0:J3}", c1))
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:13,代码来源:Complex 输出:
Formatting with ToString(): (12.1, 15.4)
Formatting with ToString(format): (12.10, 15.40)
Custom formatting with I0: 12 + 15i
Custom formatting with J3: 12.100 + 15.400j
注:本文中的System.Numerics.Complex结构体示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论