As you may know we got the BigNumberMBS class with a 320 bit floating point number to calculate with really big numbers. Now we got a new class for integer calculations. The new LargeNumberMBS class provides an integer which dynamically ranges from 0 to 4128 bits depending on the size of the number. Over 4000 bits is enough for a 1200 digit integer.
In the class we provide functions to convert from/to Xojo data types and can convert number to/from strings. We provide common functions to calculate with the large numbers, so add, subtract, multiply and divide work. We also provide modulo and a combined divide and modulo operation. You can shift bitwise left and right and do bitwise AND and OR operations. We even provide convenient functions for square and square root.
The operators are overloaded for Xojo, so you can just use the numbers like others. If you pass nil for a parameter, we take it as 0 automatically. For your convenience, the numbers convert automatically to/from string, so you can pass them directly to a msgbox.
Here is a sample code snippet, which shows that we can do math with more than 64bit to avoid an overflow with really big numbers multiplied and divided:
Dim n1 As Int64 = 10000000000 Dim n2 As Int64 = 10000000000 Dim n3 As Int64 = n1 * n2 // overflow, so wrong result Dim n4 As Int64 = n3 / n2 Dim l1 As LargeNumberMBS = LargeNumberMBS.NumberWithInt64(n1) Dim l2 As LargeNumberMBS = LargeNumberMBS.NumberWithInt64(n2) Dim l3 As LargeNumberMBS = l1 * l2 Dim l4 As LargeNumberMBS = l3 / l1 Dim s4 As String = l4.StringValue // this is correct BreakPlease try this with next prerelease. Please do not hesitate to contact us with questions.