I wanted to know how the BigInt and other such stuff are implemented. I tried to check out JAVA source code, but it was all Greek and Latin to me. Can you please explain me the algo in words - no code, so that i understand what i am actually using when i use something from the JAVA API. regards
标签:
biginteger
相关问题
- What is the proper way to construct a BigInteger f
- get random BigInteger in range (x, y) [duplicate]
- Why to avoid biginteger instantiation in Java
- Square Root for Bigint in F#
- converting int to/from System.Numerics.BigInteger
相关文章
- Why BigInteger in java is designed to be immutable
- Sum a list of BigIntegers
- 128 bit arithmetic on x64 in C
- Why doesn't my processor have built-in BigInt
- Recursive function calculating factorials leads to
- Alternative to BigInteger.ModPow(); in C#
- Parallel calculation of BigInteger factorial
- Performace of BigDecimal vs. BigInteger and BigDec
Conceptually, the same way you do arbitrary size arithmentic by hand. You have something like an array of values, and algorithms for the various operations that work on the array.
Say you want to add
100
to901
. You start with the two numbers as arrays:When you add, your addition algorithm starts from the right, takes
0+1
, giving1
,0+0
, giving0
, and -- now the tricky part --9+1
gives10
, but now we need to carry, so we add 1 to the next column over, and put(9+1)%10
into the third column.When your numbers grow big enough -- greater than 9999 in this example -- then you have to allocate more space somehow.
This is, of course, somewhat simplified if you store the numbers in reverse order.
Real implementations use full words, so the modulus is really some large power of two, but the concept is the same.
There's a very good section on this in Knuth.