Division with really big numbers

后端 未结 3 1486
终归单人心
终归单人心 2021-01-23 10:50

I was just wondering what different strategies there are for division when dealing with big numbers. By big numbers, I mean ~50 digit numbers .

e.g. 9237639100273856744

相关标签:
3条回答
  • 2021-01-23 11:30

    if you don't need very exact result, you can use logarithms and exponents. Exponent is the function f(x)=e^x, where e is a mathmaticall constant equal to 2.71828182845...
    Logarithm (marked by ln) is the inverse of the exponent.

    Since ln(a/b)=ln(a)-ln(b), to calculate a/b you need to:
    Calculate ln(a) and ln(b) [By library function, logarithm table or other methods]
    substruct them: temp=ln(a)-lb(b)
    calculate the exponent e^temp

    0 讨论(0)
  • 2021-01-23 11:39

    What language / platform do you use? This is most likely already solved, so you don't need to implement it from scratch. E.g. Haskell has the Integer type, Java the java.math.BigInteger class, .NET the System.Numerics.BigInteger structure, etc.

    If your question is really a theoretical one, I suggest you read Knuth, The Art of Computer Programming, Volume 2, Section 4.3.1. What you are looking for is called "Algorithm D" there. Here is a C implementation of that algorithm along with a short explanation: http://hackers-delight.org.ua/059.htm

    0 讨论(0)
  • 2021-01-23 11:53

    Long division is not very complicated if you are working with binary representations of your numbers and probably the most efficient algorithm.

    0 讨论(0)
提交回复
热议问题