×

# BigInteger Arithmetic

 0 Performing arithmetic operations on BigInteger/BigDecimal tends to slow down drastically as the value increases The alternative to using BigInteger/BigDecimal arithmetic comes down to using string type data with self implemented methods for each arithmetic operation ! Will it be faster compared to BigInteger/BigDecimal arithmetic or is it slower ?? Also it'll be helpful if any other alternative is shared (p.s this is in context with JAVA) asked 26 Jun '13, 13:21 364●15●18●27 accept rate: 0%

 1 Hello, I believe that the Java implementation does a few tricks that can possibly optimize some calculations versus implementing your own operations... There are some fast algorithms based on FFT to do multiplications in supra-linear time I guess, but, other than that, I guess it's up to what you need... :) You can read more here: Java BigInteger implementation :) Also, don't do extra work and implement them on your own in Java when you have better, error-free libraries ready to use :D Or at least, don't do it unless strictly required :) Best regards, Bruno answered 26 Jun '13, 13:38 2★kuruma 17.6k●72●143●209 accept rate: 8%
 0 Hi @mecodesta, To elaborate on what @kuruma mentioned, there are optimisations in the Java BigInteger library for multiplication(Toom Cook) and modulo(Chinese Remainder) operations. There are only two places where your program using BigIntegers may need optimisation: 1) Multiplication in n*log(n) time. You need to use the FFT algorithm here. 2) The BigInteger objects are immutable. Any operation you make on this object will give you a new object with the result. This does take a lot of time, especially if you are performing lots of intermediate operations. To the rescue comes MutableBigInteger. It doesn't create too many new objects and hence you can save on time and space using this class. If you want to know more about BigIntegers, check out this tutorial or the JavaDoc. Cheers! answered 12 Jan '17, 16:04 4★gkcs 2.6k●1●11●27 accept rate: 9%
 0 You should not try using string to store numbers and then using them for your operations.Firstly, it will be a lot of work to debug, and secondly, the BigInteger and BigDecimal have the fastest implementations already and they are error-free. So I think that if you feel that you are needing something more efficient than BigInteger, you should definitely check whether your algorithm is efficient. answered 13 Jan '17, 09:25 537●7 accept rate: 10%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,180
×85
×68
×2

question asked: 26 Jun '13, 13:21

question was seen: 4,843 times

last updated: 13 Jan '17, 09:25