A Programmer's Dream

Big Numbers

Posted by Stephen Wrighton on 19 Feb 2007

I've struck up against a sort of wall in VB.Net. In one of my projects, I'm having to do math calculations on extremely large numbers (we're talking something like the result from the math operation: 5!/(26!-5!)*5! ).

As one might expect that gives overflow compiler errors for Integers, Long and Doubles. Reals just gives a decimal number.

So where does that leave me? Well it leaves me coming up with a class or method to perform math functions on large numbers when they're represented as strings.

This isn't as hard as it really sounds, for the basics of numbers is that 123 is actually 1*10^2+2*10+3*1 (for base 10 numbers, for other bases, change the 10 to whatever base you're trying to work in). Of course this is not nearly as simple as I'm probably making it sound. Regardless, I'll probably search for a working .NET implementation of this before I actually bother to build it, I just wished Microsoft had stuck it into VB.Net is all.

If anyone has any suggestions, I'd be more than willing to take them.

EDIT: After a bit of searching, I first found Lint: Large Integer Object Library. A C++ library which showed a decent amount of promise. Only problem is that it would not compile in .NET and I didn't feel up to spending the time figuring out why (though that may be a project for a later date). The other library of promise is the BigNumber library. It's a C# library for large numbers and worked quite well. There's a few things I would like to see added to this (such as inherent support for math operations between BigNumbers and other data types such as integers), and while there are some operations that could be improved a bit in terms of speed and efficenciency, overall I'm happy.

Tweet me @kidananubix if you like this post.

Tweet