Alex Rivera | Logout

Big integers in C#

Asked 2008-10-07T00:16:09.243
63

Currently I am borrowing java.math.BigInteger from the J# libraries as described here. Having never used a library for working with large integers before, this seems slow, on the order of 10 times slower, even for ulong length numbers. Does anyone have any better (preferably free) libraries, or is this level of performance normal?

Edit
Report

2 Answers

9

F# also ships with one. You can get it at Microsoft.FSharp.Math.

answered 2009-01-31T13:22:23.287
2

Yes, it will be slow, and 10x difference is about what I'd expect. BigInt uses an array to represent an arbitrary length, and all the operations have to be done manually (as opposed to most math which can be done directly with the CPU)

I don't even know if hand-coding it in assembly will give you much of a performance gain over 10x, that's pretty damn close. I'd look for other ways to optimize it--sometimes depending on your math problem there are little tricks you can do to make it quicker.

answered 2008-10-07T00:23:35.393

Your Answer