Thursday, 11 September 2008

Why Java Math Beats C# Math (Prime numerology)

Now if Java's integers don't have enough juice for you (and you must be a serious arithmetic junkie if that's the case) there is always refuge in java.math's BigInteger class.This is a perennial favourite if you want to test prime numbers. AFAIK prime numbers don't exist in C#, but hobbyists have nonetheless tried to find them using BigInteger code on codeproject.OK, partner! Let's instantiate java.math.BigIntegers! Let's find primes! To Double.POSITIVE_INFINITY and beyond!

3 comments:

Bill Ellis said...

Absolutely. C# not having a BigInteger class in today's day and age harks back to the day when MSDOS could only address 1 meg of memory. A Visual Studio user today may still use the BigInteger class in J#, but its BigInteger.IsProbablePrime() method freezes on certain numbers, e.g. on 117137, if I remember correctly. Visual Studio J++ 6.0 works fine (probably using licensed code from Sun), but the last time I tried, J++ 6.0 wouldn't work under Vista.

KolleyKibber said...

Thanks for the awesome post Bill. I never checked out BigInt in VJ++ but this is just ANOTHER example of Microsoft taking power out of the hands of beneficient programmers bent on changing the world. Each upgrade takes us from average functionality to low or no functionality. Example - What's with MS Paint in Vista?! PaintBrush in Windows 3.1 was a power tool in comparison. Get your socks on, Microsoft!

KolleyKibber said...

Sun also had problems in their isProbablePrime implementation back in the heyday of JDK1.3 but dig out the old test cases, run them in 1.6 and you'll see they fixed it. Java core math still dominates .Net period. But what about scripting languages with BUILT-IN BigInt functionality? No need to "new" BigInt's any more just to do simple arithmetic!