Platforms to show: All Mac Windows Linux Cross-Platform
/DataTypes/GCD with LargeNumber
Required plugins for this example: MBS DataTypes Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DataTypes/GCD with LargeNumber
This example is the version from Wed, 2nd Apr 2019.
Project "GCD with LargeNumber.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
Dim a As New LargeNumberMBS(3245*456)
Dim b As New LargeNumberMBS(4356*456)
Dim m1 As Double = Microseconds
Dim l As LargeNumberMBS = FindGCD(a,b)
Dim m2 As Double = Microseconds
Dim ma As LargeNumberMBS = a / l
Dim mb As LargeNumberMBS = b / l
Dim m3 As Double = Microseconds
Dim p As LargeNumberMBS = a.FindGCD(b)
Dim m4 As Double = Microseconds
Dim md1 As Double = m2-m1
Dim md2 As Double = m4-m3
MsgBox "FindGCD("+a.StringValue+", "+b.StringValue+") = "+l.StringValue+" or via plugin "+p.StringValue+EndOfLine+ma.StringValue+" "+mb.StringValue
End EventHandler
Function FindGCD(ParamArray n() As LargeNumberMBS) As LargeNumberMBS
#Pragma DisableBackgroundTasks
// Greatest Common Divisor
' (the largest number that divides the given numbers without remainder)
Dim x As Integer
Dim j, k, One, theGCD As LargeNumberMBS
For x = 0 To n.UBound - 1
theGCD = New LargeNumberMBS(1)
If n(x) > n( x+1 ) Then
k = n(x)
Else
k = n( x+1 )
End If
j = k
One = New LargeNumberMBS(1)
While Not j.isZero
If n(x).modulo(j).IsZero And n( x + 1 ).modulo(j).IsZero Then
theGCD = j
Exit While
End If
j = j - One
Wend
n( x + 1 ) = theGCD
Next
Return theGCD
End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS DataTypes Plugin.