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

Does anyone care to offer an efficient algorithm on how best to do this?

Skip to content
# Most efficient implementation of a large number class

###### Related Question

bignumlanguage-agnostic

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

Does anyone care to offer an efficient algorithm on how best to do this?

- Interface vs Base class
- How to detect Credit card type based on number
- What’s your most controversial programming opinion
- Hash functions use a prime number modulus
- R – Finding prime factors to large numbers using specially-crafted CPUs
- C++ – Efficient Multiply/Divide of two 128-bit Integers on x86 (no 64-bit)

## Best Solution

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:Design your own class/structure containing multiple higher order datatypes like double or int64 variables and define basic math operations for them using operator overloading (in C++) or via methods named add, subtract, multiply, shift, etc. (in JAVA and other OO languages).Let me know if you need any further help. I have done this a couple of times in the past.