Strange Brouhaha

Thursday, December 29, 2005

Big integers in C#

I'm trying to brush up on my C# coding for work, and part of the way I'm doing that is by porting some of my Java code to C#. I'm running into a problem that was trivial to solve in Java, but turns out to be not so trivial to solve (in a small amount of space, at least for me) in C#.

Perhaps someone smarter than me knows.

The problem is this: I need to be able to calculate 100! with a greater degree of precision than is available in the double type. The C# double is only good for 16 digits. I need the whole thing. In Java, a person just uses BigInteger. There's no built-in equivalent in C#.

Tan's BigInteger class works, but it's too big. I realize I should just study that. I suppose I've answered my own question...

2 Comments:

  • True, there's no built-in to the BCL, but you can use the J# redistributable and then you'll have the BigInteger from Java and can use it like you used to just fine.

    This came up on IRC a few days ago, actually :)

    http://blog.sublogic.com/2005/12/the-net-framework-library-really-needs-a-biginteger/

    By Anonymous Anonymous, at 10:34 PM  

  • Thanks, James. I saw that I could do that when I was poking around yesterday morning, and I was hoping that I could avoid using stuff outside the BCL. I'm trying to avoid Visual Studio shenanigans while I get the language side down--but I'm probably going to be in the same boat as you ("former Java and Eclipse guy") before too long.

    My Java is a lot better than my C#...but my new employer is a C# house. Fortunately (and you should all breathe a sigh of relief) I'm in QA and just need to use C# for automated testing, not production code.

    By Blogger Robert, at 7:53 AM  

Post a Comment

<< Home