New Math Functions in VB.Net

Posted
Comments None

The VB.Net code for the new math functions that were added to the built-in math functions of GeneXproTools with Mini-Release 1 is very similar to both the Visual Basic code and Excel VBA code, except that in VB.Net there is a "Return" statement (like in C# or C++), you can declare and initialize variables at the same time, and you also have access to native Min and Max functions. And like we did with the C# code, we are also keeping the code for evaluating min and max values in the places where argmin and argmax values are evaluated for the sake of uniformity across all programming languages that GeneXproTools supports.

Here's the VB.Net code for all the new math functions that are now part of the VB.Net Grammar of GeneXproTools:

    Function gepRamp1(ByVal x As Double) As Double
        If x > 0.0 Then
            Return x
        Else
            Return 0.0
        End If
    End Function

    Function gepRamp2(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 0.0
        Else
            Return x
        End If
    End Function

    Function gepRamp3(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 0.0
        Else
            Return -x
        End If
    End Function

    Function gepRamp4(ByVal x As Double) As Double
        If x > 0.0 Then
            Return -x
        Else
            Return 0.0
        End If
    End Function

    Function gepStep1(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 1.0
        Else
            Return -1.0
        End If
    End Function

    Function gepStep2(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepStep3(ByVal x As Double) As Double
        If x >= 1.0 Then
            Return 1.0
        ElseIf x <= -1.0 Then
            Return -1.0
        Else
            Return x
        End If
    End Function

    Function gepStep4(ByVal x As Double) As Double
        If x >= 1.0 Then
            Return 1.0
        ElseIf x <= 0.0 Then
            Return 0.0
        Else
            Return x
        End If
    End Function

    Function gepCL2A(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        Else
            Return -1.0
        End If
    End Function

    Function gepCL2B(ByVal x As Double, ByVal y As Double) As Double
        If x >= 0.0 And y < 0.0 Then
            Return -1.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2C(ByVal x As Double, ByVal y As Double) As Double
        If x > 1.0 And y < -1.0 Then
            Return -1.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2D(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL2E(ByVal x As Double, ByVal y As Double) As Double
        If x >= 0.0 And y <= 0.0 Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2F(ByVal x As Double, ByVal y As Double) As Double
        If x > 1.0 And y < -1.0 Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL3A(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y < 0.0 Then
            Return 1.0
        ElseIf x < 0.0 And y > 0.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL3B(ByVal x As Double, ByVal y As Double) As Double
        If x >= 1.0 And y >= 1.0 Then
            Return 1.0
        ElseIf x <= -1.0 And y <= -1.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL3C(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        ElseIf x < 0.0 And y < 0.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return -1.0
        ElseIf y > (x + SLACK) Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        If z < minValue Then
            Return -1.0
        ElseIf z > maxValue Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim minValue As Double = Min(Min(a,b),c)
        Dim maxValue As Double = Max(Max(a,b),c)
        If d < minValue Then
            Return -1.0
        ElseIf d > maxValue Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap4A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < x Then
            Return 1.0
        ElseIf y >= x And y < (x + SLACK) Then
            Return 2.0
        ElseIf y >= (x + SLACK) Then
            Return 3.0
        End If
    End Function

    Function gepMap4B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        ' evaluate minValue(x,y), maxValue(x,y) and midrange
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim midrange As Double = (maxValue + minValue)/2.0
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midrange Then
            Return 1.0
        ElseIf z >= midrange And z < maxValue Then
            Return 2.0
        ElseIf z >= maxValue Then
            Return 3.0
        End If
    End Function

    Function gepMap4C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then
            midleValue = a
        End If
        If 1 <> argMin And 1 <> argMax Then
            midleValue = b
        End If

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midleValue Then
            Return 1.0
        ElseIf d >= midleValue And d < maxValue Then
            Return 2.0
        ElseIf d >= maxValue Then
            Return 3.0
        End If
    End Function

    Function gepMap5A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 15.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < (x - SLACK/3.0) Then
            Return 1.0
        ElseIf y >= (x - SLACK/3.0) And y < (x + SLACK/3.0) Then
            Return 2.0
        ElseIf y >= (x + SLACK/3.0) And y < (x + SLACK) Then
            Return 3.0
        ElseIf y >= (x + SLACK) Then
            Return 4.0
        End If
    End Function

    Function gepMap5B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        ' evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim intervalLength As Double = (maxValue - minValue)/3.0
        Dim midpoint1 As Double = minValue + intervalLength
        Dim midpoint2 As Double = minValue + 2.0*intervalLength
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midpoint1 Then
            Return 1.0
        ElseIf z >= midpoint1 And z < midpoint2 Then
            Return 2.0
        ElseIf z >= midpoint2 And z < maxValue Then
            Return 3.0
        ElseIf z >= maxValue Then
            Return 4.0
        End If
    End Function

    Function gepMap5C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then midleValue = a
        If 1 <> argMin And 1 <> argMax Then midleValue = b
        Dim midrange1 As Double = (minValue + midleValue)/2.0
        Dim midrange2 As Double = (midleValue + maxValue)/2.0

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midrange1 Then
            Return 1.0
        ElseIf d >= midrange1 And d < midrange2 Then
            Return 2.0
        ElseIf d >= midrange2 And d < maxValue Then
            Return 3.0
        ElseIf d >= maxValue Then
            Return 4.0
        End If
    End Function

    Function gepMap6A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < (x - SLACK/2.0) Then
            Return 1.0
        ElseIf y >= (x - SLACK/2.0) And y < x Then
            Return 2.0
        ElseIf y >= x And y < (x + SLACK/2.0) Then
            Return 3.0
        ElseIf y >= (x + SLACK/2.0) And y < (x + SLACK) Then
            Return 4.0
        ElseIf y >= (x + SLACK) Then
            Return 5.0
        End If
    End Function

    Function gepMap6B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim midrange As Double = (minValue + maxValue)/2.0
        Dim midpoint1 As Double = (minValue + midrange)/2.0
        Dim midpoint2 As Double = (midrange + maxValue)/2.0
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midpoint1 Then
            Return 1.0
        ElseIf z >= midpoint1 And z < midrange Then
            Return 2.0
        ElseIf z >= midrange And z < midpoint2 Then
            Return 3.0
        ElseIf z >= midpoint2 And z < maxValue Then
            Return 4.0
        ElseIf z >= maxValue Then
            Return 5.0
        End If
    End Function

    Function gepMap6C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then midleValue = a
        If 1 <> argMin And 1 <> argMax Then midleValue = b
        ' evaluate midrange1 and midrange2
        Dim midrange1 As Double = (minValue + midleValue)/2.0
        Dim midrange2 As Double = (midleValue + maxValue)/2.0

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midrange1 Then
            Return 1.0
        ElseIf d >= midrange1 And d < midleValue Then
            Return 2.0
        ElseIf d >= midleValue And d < midrange2 Then
            Return 3.0
        ElseIf d >= midrange2 And d < maxValue Then
            Return 4.0
        ElseIf d >= maxValue Then
            Return 5.0
        End If
    End Function

    Function gepECL3A(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y > x And z < x Then
            Return 1.0
        ElseIf y < x And z > x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y > x And z > x Then
            Return 1.0
        ElseIf y < x And z < x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3C(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y >= x And z >= x Then
            Return 1.0
        ElseIf y <= -x And z <= -x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3D(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim minValue As Double = Min(a,b)
        Dim maxValue As Double = Max(a,b)
        If c >= maxValue And d >= maxValue Then
            Return 1.0
        ElseIf c <= minValue And d <= minValue Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepAMin2(ByVal x As Double, ByVal y As Double) As Double
        If x < y Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepAMin3(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim temp As Double = x
        Dim argMin As Double = 0.0
        If temp >= y Then
            temp = y
            argMin = 1.0
        End If
        If temp >= z Then argMin = 2.0
        Return argMin
    End Function

    Function gepAMin4(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim temp As Double = a
        Dim argMin As Double = 0.0
        If temp >= b Then
            temp = b
            argMin = 1.0
        End If
        If temp >= c Then
            temp = c
            argMin = 2.0
        End If
        If temp >= d Then argMin = 3.0
        Return argMin
    End Function

    Function gepAMax2(ByVal x As Double, ByVal y As Double) As Double
        If x >= y Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepAMax3(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim temp As Double = x
        Dim argMax As Double = 0.0
        If temp < y Then
            temp = y
            argMax = 1.0
        End If
        If temp < z Then argMax = 2.0
        Return argMax
    End Function

    Function gepAMax4(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim temp As Double = a
        Dim argMax As Double = 0.0
        If temp < b Then
            temp = b
            argMax = 1.0
        End If
        If temp < c Then
            temp = c
            argMax = 2.0
        End If
        If temp < d Then argMax = 3.0
        Return argMax
    End Function

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →