Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

language agnostic - Most efficient implementation of a large number class

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...