Structures
'floats for real and imaginary parts of complex numbers
'or use both for simple float math
Public real, unreal As Double
Public Sub New(ByVal re As Double, ByVal unre As Double)
real = re
unreal = unre
End Sub
Public ReadOnly Property BasicProduct()
Get
BasicProduct = real * unreal
End Get
End Property
Public ReadOnly Property BasicDivide()
Get
BasicDivide = real / unreal
End Get
End Property
Public ReadOnly Property Reciprocal() As Complex
Get
If real = 0.0 And unreal = 0.0 Then
Throw New DivideByZeroException()
End If
Dim div As Double = real * real + unreal * unreal
Return New Complex(real / div, −unreal / div)
End Get
End Property
Public Shared Function ComplexToDouble(ByVal aReal As Complex) _
As Double
Return aReal.real
End Function
Public Shared Function RealToComplex(ByVal dble As Double) _
As Complex
Return New Complex(dble, 0.0)
End Function
Public Shared Function ToPositive(ByVal aReal As Complex) _
As Complex
Return aReal
End Function
Public Shared Function ComplexToNegative(ByVal areal As Complex) _
As Complex
Return New Complex(−areal.real, −areal.unreal)
End Function
Public Shared Function AddComplex(ByVal areal As Complex, _
ByVal breal As Complex) As Complex
Return New Complex(areal.real + breal.real, areal.unreal + _
breal.unreal)
End Function
Public Shared Function SubtractComplex(ByVal areal As Complex, _
ByVal breal As Complex) As Complex
Return New Complex(areal.real − breal.real, areal.unreal − _
breal.unreal)
End Function
241