# Large integer numbers in Xojo

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:

[code]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
Break[/code]

Excellent news, Christian! Big primes and faster crypto math!

Move over, Montgomery Multiplier, here I come!

Good !!
with mod_pow, mod_Inverse, random_generator and calculate_probable_prime_number function u can write RSA crypt, decrypt, and key pair generate function …

If needed, I could just add more methods.
And RSA creation, well if you need that, we could probably add a method for this, too.

19.1pr5 is on the website, so you can try.

This is a very good news Christian. Waiting for this since years.
Now what about a fixed decimal type, maybe based on this class?

The BigNumber can indeed handle very big decimal numbers, but the floating point error is always there…

You can make your own big currency data type on top of both.
Just keep your currency there multiplied by a high factor like 1000000.

[quote=426691:@Christian Schmitz]You can make your own big currency data type on top of both.
Just keep your currency there multiplied by a high factor like 1000000.[/quote]

Yes, that’s why I’m happy about LargeNumberMBS
Though a decimal arithmetics handled in plugin would be much more performant.

I’ll add a dozen more methods for next pr.

We got more methods including:

• Increment and Decrement
• Integer Divide/Modulo/Multiply
• Prime and IsPrime functions
• And module functions: ModInverse, ExpMod, SqrMod, MulMod, AddMod, SubMod

We can get more if needed.

This sounds amazing!