Arbitrary precision arithmetic

Viewed 15

In the article https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

they present a algorithm. I'm having trouble with this because in the second while block. for the first n, carry(0.1) / Base just sets the carry to carry divided by 10 which is a infinitely increasing smaller number of more digits. But is never < 0.

trying to create this in python

Limit = 1000
Base = 10
FactorialLimit = 3
digit = {}
carry = 0
d = 0
digit[1] = 1
last = 1
for n in range(1, FactorialLimit):
    carry = 0
    for i in range(1, last + 1):
        d = digit[i] * n + carry
        digit[i] = d%Base
        carry = d / Base

    while carry > 0:
        if last > Limit:
            raise
        last = last + 1
        digit[last] = carry % Base
        carry = carry / Base

    print(carry)
print(digit)

But something has gone clearly wrong or I don't understand at all

0 Answers
Related