Most efficient large class implementation

When performing calculations on very large numbers, where integral data types such as double or int64 are reduced, a separate class may be needed to handle such large numbers.

Does anyone want to suggest an efficient algorithm, what is the best way to do this?

+6
language-agnostic bignum
source share
5 answers

In C # 4.0 use the BigInteger type

+6
source share

There are 2 solutions to your problem:

  • Easy way: Use an external library such as the GNU MP Bignum Library and forget about implementation details.

  • Hard way: Create your own class / structure containing several higher-order data types, such as double or int64 variables, and define basic mathematical operations for them using operator overloading (in C ++) or using methods called add, subtract, multiply, shift, etc. (In JAVA and other OO languages).

Let me know if you need more help. I have done this several times in the past.

+12
source share

Using the built-in language features for me.

Java has BigInteger and BigDecimal , and the Python automaton switches to an object similar to Java if the number falls outside the integer or whatnot range.

As for other languages, I have no idea.

I don't like reinventing the wheel.

+4
source share

You ask arithmetic of arbitrary accuracy , the topic on which they were written . If you need a simple and reasonably efficient BigNum library for C #, you can check out IntX .

+4
source share

Running your own BigNum library is more complicated, so I would say like jjnguy. Use everything your language offers as libraries.

In .net, reference the VisualJ DLL as they contain the BigInteger and BigDecimal classes. However, you should be aware of some of the limitations of these libraries, such as the lack of a square root method.

+3
source share

All Articles